装备合成

装备合成

https://ac.nowcoder.com/acm/problem/200211

思路分析:

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
typedef long long LL;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int T;
    LL x,y;
    cin>>T;
    while( T-- ){
        cin>>x>>y;
        LL _left=0,_right=1e9,ans;
        while( _left <= _right ){
            LL mid=_left+_right >> 1;
            LL sumA=max(4*mid-x,0ll),sumB=min(2*mid,y-mid);
            if( sumA == sumB && sumA & 1 ) _right=mid-1;
            else if(sumA > sumB) _right=mid-1;
            else{
                _left=mid+1;
                ans=mid; 
            }
        } 
        cout<<ans<<endl;
    } 
    return 0;
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务