RPG Protagonist

RPG Protagonist
在这里插入图片描述

思路

首先肯定不能直接贪心做,如果对于某个人去最优的方案,第二个人就不一定最优了。

注意到 c n t cnt cnt 值很小。所以可以考虑枚举第一个人拿了多少把剑,剩余的肯定尽可能拿战斧。第二个人就可以贪心拿重量小的武器知道拿光,然后拿另外一个。

#include <bits/stdc++.h>
 
using namespace std;
int f,p,cnts,cntw,s,w;
int main() {
    
    
    int _;
    scanf("%d", &_);
    while (_--) {
    
    
        scanf("%d%d%d%d%d%d", &f, &p, &cnts, &cntw, &s, &w);
        if (s > w) {
    
    
            swap(s, w);
            swap(cnts, cntw);
        }
        int f2 = 0, p2 = 0, p1 = 0, ans = 0;
        for (int f1 = 0; f1 <= cnts && f1 <= f / s; 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);
        }
        printf("%d\n", ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43601103/article/details/112981787
RPG