CF-1183C Computer Game
基本思路
\[\begin{array}{l}
k,n,a,b,假设能完成游戏,则有\\
x_1+x_2=n\\
x_1*a+x_2*b<k\\
由于 \quad a<b \quad则有\\
x_1*(a-b)+(x_1+x_2)*b<k\\
x<\frac{k-n*b}{a-b}
\end{array}
复杂度O(1)
\]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,k,n,a,b;
int main()
{
cin>>q;
while(q--)
{
cin>>k>>n>>a>>b;
ll x;
if((k-b*n)<=0) cout<<-1<<endl;
else
{
x=(k-n*b)/(a-b);
if((k-n*b)%(a-b)==0)x--;
cout<<min(x,n)<<endl;
}
}
return 0;
}