美文网首页
poj3175 枚举

poj3175 枚举

作者: 暖昼氤氲 | 来源:发表于2019-11-29 20:50 被阅读0次
     /*
    Time:2019.11.29
    Author: Goven
    type:枚举 
    err:Time Limit Exceeded(开根号循环的数字是double)
    ref:
    */ 
    #include<iostream>
    #include<cmath> 
    #include<string> 
    using namespace std;
    
    int main()
    {
        int l, j, i = 2;
        double a;
        string s;
        cin >> l >> s;
        while (1) {
            a = sqrt((double)i);
            a = a - (int)a;
            for (j = 0; j < l; j++) {
                int b = (int)(a * 10);
                a = a * 10; 
                b = b % 10;
                if ((s[j] - '0') != b) break;
            }
            if (j == l) break;
            i++;
            
        }
        cout << i << endl;
        return 0;
    }
    
    
    /*正确版 
    ref:https://blog.csdn.net/qq_31785871/article/details/52972893
    https://blog.csdn.net/aozil_yang/article/details/52057775
    */
    #include<iostream>
    #include<cmath> 
    #include<string> 
    
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        int n, l;
        cin >> l >> n;
        double base = pow(0.1, l), t = base * n;
        int i = 1;
        while (1) {
            double a = (ll)((i + t) * (i + t) + 1), b = (i + t + base) * (i + t + base);
            if (a + 1e-11 < b) {//err1:不加 1e-11 就是错的 
                printf("%lld\n", (ll)a);
                break;
            }
            i++;
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:poj3175 枚举

          本文链接:https://www.haomeiwen.com/subject/kyfnwctx.html