1400B 1700的题
题意:两个人有p和f的金币,一个店铺里有cnts把剑,cntw把斧头,剑的价值是s,斧头的价值是w,两人的金币不能合起来用,问如何买才能得到最多数量的工具
思路:贪心,设剑的价值更小,首先把价值更小的全部买完,如果不行,直接打印,如果能,那么对第一个人枚举买剑的数量,同时在此情况下,能买最多斧头,另一个人把剩下的剑买完,然后在买最多数量的斧头即可
代码如下:
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 1e5+10;
#define int ll
inline int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
return x*f;
}
inline void cf(){
int t = read();
while(t--){
int p=read(), f=read(), cnts=read(), cntw=read(), s=read(), w=read();
if(s>w)swap(cnts, cntw), swap(s,w);
int ans = 0;
if(p/s+f/s<=cnts){
printf("%lld\n",p/s+f/s);
continue;
}
rep(i,0,cnts){ //枚举p拿的s的个数
int x = min(cntw, (p-i*s)/w); //p最多能拿w的个数
// printf("%lld\n", p-i*s);
if((p-i*s)<0) break; //如果p已经拿不了这么多s的话,直接跳出循环
int y = min(cntw-x, (f-(cnts-i)*s)/w); //f在把s拿完的情况下最多能拿w的个数
if((f-(cnts-i)*s)<0) continue;
ans = max(ans, cnts+y+x);
}
printf("%lld\n", ans);
}
return ;
}
signed main(){
cf();
return 0;
}