codeforces1217A - Creating a Character

有必要挂下提醒下,写了个巨蠢的判断,菜得真实

思路:判断一下str最小的能够比iq大的就好了,用二分查找找出

#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0),cout.tie(0);
    int T,str,iq,exp;      cin>>T;
    while(T--)
    {
        cin>>str>>iq>>exp;
        int l = 0,r = exp;
        while(l<=r)
        {
            int mid = (l + r) >> 1;
            if(str + mid > iq + exp - mid)
                r = mid - 1;
            else
                l = mid + 1;
        }
        cout<< exp - l + 1 <<'\n';
    }   
}

  

posted on 2019-10-07 17:46  chengyulala  阅读(115)  评论(0编辑  收藏  举报

导航