7.7竞赛题目选讲(等待更新中,笔者先跑路到第八章了
Zombie's Treasure Chest:
点击查看笔者代码
#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
ull gcd(ull a, ull b) {
if(a%b == 0) return b;
return gcd(b, a%b);
}
int main() {
int t;
cin >> t;
for(int i = 1; i <= t; i++) {
ull n, v1, s1, v2, s2, ans, add = 0;
cin >> n >> v1 >> s1 >> v2 >> s2;
if(v1 < v2) {
int temp = v1; v1 = v2; v2 = temp;
temp = s1; s1 = s2; s2 = temp;
}
ull dis = gcd(v1, v2);
ull mul = v1*v2/dis, base = max(v1*s2/dis, v2*s1/dis);
if(n/mul > 1) { ans = (n/mul-1)*base; n = n % mul + mul; }
else ans = 0;
int len = n / v1;
for(int j = 0; j <= len; j++)
add = max(add, j*s1+(n-j*v1)/v2*s2);
cout << "Case #" << i << ": " << ans+add << endl;
}
return 0;
}