美文网首页
POJ3685(二分套二分)

POJ3685(二分套二分)

作者: Alan66 | 来源:发表于2017-07-17 10:38 被阅读0次
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    #define INF 1e9+7
    typedef long long ll;
    
    ll maxn, m;  //如果用int会WA,我也不知道为什么
    ll Sum(ll x, ll y)
    {
        ll ans = x*x + 100000 * x + y*y - 100000 * y + x*y;
        return ans;
    }
    
    ll Binarysearch(ll x)
    {
        ll sum = 0;
        for (ll j = 1; j <= maxn; j++) {
            int lb = 0, rb = maxn + 1;
            while (rb - lb >1) {
                ll mid = (lb + rb) / 2;
                if ( Sum(mid, j) < x) lb = mid;
                else rb = mid;
            }
            sum += (rb - 1);
        }
    
        return sum;
    }
    
    int main()
    {
        int T;
        scanf("%d", &T);
        while (T--)
        {
            scanf("%lld%lld", &maxn, &m);
            ll rb = 1e12, lb = -1e12;
            while (rb - lb > 1) {
                ll mid = (lb + rb) / 2;
                if (Binarysearch(mid) < m) lb = mid;
                else rb = mid;
            }
            printf("%lld\n", rb - 1);
        }
    
    
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:POJ3685(二分套二分)

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