本文主要是介绍例题 7-11 宝箱(Zombie‘s Treasure Chest, Shanghai 2011, UVa12325),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:https://vjudge.net/problem/UVA-12325
分类:分类枚举
备注:两种枚举法,好题
注意开long long
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll lim = 1 << 16;
int main(void){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T;ll n, s1, v1, s2, v2;scanf("%d",&T);for(int cas = 1; cas <= T; cas++){scanf("%lld %lld %lld %lld %lld", &n, &s1, &v1, &s2, &v2);ll ans = 0;if(n / s1 <= lim){for(int i = 0; i * s1 <= n; i++)ans = max(ans, i * v1 + (n - i * s1) / s2 * v2); }else if(n / s2 <= lim){for(int i = 0; i * s2 <= n; i++)ans = max(ans, i * v2 + (n - i * s2) / s1 * v1);}else{if(s2 * v1 > s1 * v2){//同体积, 宝物1性价比高, 则宝物2选取的范围为[0,s1)for(int i = 0; i < s1; i++)ans = max(ans, i * v2 + (n - i * s2) / s1 * v1);}else{for(int i = 0; i < s2; i++)ans = max(ans, i * v1 + (n - i * s1) / s2 * v2);}}printf("Case #%d: %lld\n", cas, ans);}return 0;
}
这篇关于例题 7-11 宝箱(Zombie‘s Treasure Chest, Shanghai 2011, UVa12325)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!