首页 > 其他分享 >Codeforces Round #570 (Div. 3) C. Computer Game(二分)

Codeforces Round #570 (Div. 3) C. Computer Game(二分)

时间:2022-10-07 20:46:04浏览次数:71  
标签:const LL 570 Codeforces Game ans 15

https://codeforces.com/contest/1183/problem/C

题目大意:

给定k的总时间,必须玩n局,每一局正常消耗a时间,插电玩消耗b时间

问我们在能>0的剩余时间内玩完这n局下的可以最大消耗a时间的局数是多少?

注意:剩余时间>0并且玩完了这n局才算整整意义上赢了。否则输出-1。
input 
6
15 5 3 2
15 5 4 3
15 5 2 1
15 5 5 1
16 7 5 2
20 5 7 3
output 
4
-1
5
2
0
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=200200,M=2002;
LL k,n,a,b,ans=0;
bool check(LL x)
{
    //不能超过n次,也不能低于0次
    if((x*a+(n-x)*b)<k) return true;
    else return false;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        ans=0;
        cin>>k>>n>>a>>b;
        if(n*b>=k) cout<<"-1"<<endl;
        //else if(n*a<k) cout<<n<<endl;
        else
        {
            LL l=0,r=n;//最大的次数就是r这么多
            while(l<=r)
            {
                LL mid=(l+r)/2;
                //cout<<mid<<endl;

                if(check(mid)==true)//满足条件,往大了找
                {
                    ans=max(ans,mid);
                    l=mid+1;
                }
                else r=mid-1;//不满足,往小了找
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

标签:const,LL,570,Codeforces,Game,ans,15
From: https://www.cnblogs.com/Vivian-0918/p/16762015.html

相关文章