Candies CodeForces - 991C(二分水题)

就是二分暴力就好了

为什么要记下来 呵呵。。。。emm你说为什么。。。

行吧

好吧

我一直以为我的二分出问题了

原来不是 依旧很帅

统计的时候求的减了多少次  然后用次数乘了mid 这样做会使那个人获得的数量大于精确值。。我以为没事来。。还是太天真

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
typedef long long LL;
LL n, k;

int main()
{
    scanf("%lld", &n);
    if(n <= 42)
    {
        cout<< 1 <<endl;
        return 0;
    }
    LL tmp = n;
    LL l = 0, r = n;

    while(l <= r)
    {
        LL sum = 0;
        tmp = n;
        LL mid = l + (r - l) / 2;
        while(tmp > 0)
        {
            LL t = min(mid, tmp);
            tmp -= t;
            tmp -= tmp / 10;
            sum += t;
        }
        if(sum >= (n+1) / 2) r = mid - 1;
        else l = mid + 1;
    }
    cout<< l <<endl;


    return 0;
}

猜你喜欢

转载自www.cnblogs.com/WTSRUVF/p/9550618.html