题目描述:有x个数你有n个选择 每个选择会减少d个数,然后增加h个数(当前的数数不小于0),可以任意选择,并输出总共最少的次数
分析:选择收获最大的那一组,并且找出一次减的最多的那一组
ad代码:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int a,b,x,n,mx1,mx2;
//int solve(int cur,int cnt){
// if(cur<=mx2)return cnt+1;
// if(cur%a==0) return solve(cur/a*(b-1)+a,cnt+cur/a-1);
// return solve(cur%a+cur/a*b,cnt+cur/a);
//}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
// int n,x;
int cnt=0x3f3f3f3f;
mx1=-1000000000,mx2=-1;
cin>>n>>x;
while(n--){
int a1,b1;
cin>>a1>>b1;
if(mx1<a1-b1)a=a1,b=b1,mx1=a1-b1;
mx2=max(mx2,a1);
}
if(x<=mx2)cout<<1<<endl;
else if(mx1<=0) cout<<-1<<endl;
else {
cout<<1+(int)ceil((x-mx2)*1.0/mx1)<<endl;
}
}
}

京公网安备 11010502036488号