题意:有两个口袋,容量分别为f和p,有两种物品,一种数量为cnts,重量为s,一种数量为cntw,重量为w,问最多可以装下多少件物品。
我们假设s为较轻的一种,因为只要求数量,所以我们的想法当然是尽量装较轻的一种,但往第一个袋子一直装s最终装的物品不一定是最多的,毕竟会有很多的"恰巧"。所以我们不能一股脑的往第一个袋子塞s,而是需要权衡第一个袋子放多少s,第二个袋子放多少s,cnt最大为2e5,所以我们可以遍历第一个袋子放入s的数量,通过给出的数据之间的关系我们可以计算出将一个袋子放不下或没东西放的情况下总共装入物品的数量。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
deque<int> dqmin, dqmax;
const int N = 1e5 + 100;
const int mod = 1e9;
ll arr[N];
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int f, p, cnts, cntw, s, w;
cin >> f >> p >> cnts >> cntw >> s >> w;
if (s > w) {
swap(s, w);
swap(cnts, cntw);
}
int f1 = 0, f2 = 0, p1 = 0, p2 = 0, ans = 0;
for (int f1 = 0; f1 <= f / s && f1 <= cnts; f1++) {
f2 = min(cntw, (f - s * f1) / w);
p1 = min(cnts - f1, p / s);
p2 = min(cntw - f2, (p - s * p1) / w);
ans = max(ans, f1 + f2 + p1 + p2);
f2 = p1 = p2 = 0;
}
cout << ans << endl;
}
}