链接
http://codeforces.com/contest/1183/problem/C
题意
开始Vova的笔记本电脑电量为k,1.如果电量大于a,它可以进行一次游戏,之后总电量会减去a,2.如果电量大于b,那么它也可以进行一次游戏并同时充电,之后总电量减b,如果电量小于等于b,他想要进行n次游戏,并且希望尽可能多的进行第一种游戏方式(即不充电的),最后输出第一种游戏的次数,如果不能进行n次游戏就输出-1;
题解
本题即求满足ax+by<k的最大的x
代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define inf 0x7f7f7f7f
#define maxn 100006
#define mod 1000000007
#define N 1
#define P 2
typedef long long ll;
typedef struct {
int u, v, next, w;
} Edge;
Edge e[1];
int cnt, head[1];
inline void add(int u, int v,int w) {
e[cnt].u = u;
e[cnt].v = v;
e[cnt].w = w;
// e[cnt].f=f;
e[cnt].next = head[u];
head[u] = cnt++;
e[cnt].u = v;
e[cnt].v = u;
e[cnt].w = w;
// e[cnt].f=-f;
e[cnt].next = head[v];
head[v] = cnt++;
}
inline void write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
ll k,n,a,b,q;
int main(){
q=read();
while(q--){
k=read(),n=read(),a=read(),b=read();
if(k<=n*b)
cout<<-1<<endl;
else if(k>n*a){
cout<<n<<endl;
}else{
k=n*a-k;
ll t=a-b;
ll p=k/t+1;
cout<<n-p<<endl;
}
}
}