标签:
先考虑性价,假设宝石1性价比高于宝石2,则宝石2最多不可能拿超过lcm(s1, s2) / s2个
枚举性价比较低的宝石拿多少个即可
1 #include <bits/stdc++.h> 2 3 long long n, s1, s2, v1, v2; 4 5 long long gcd(long long a, long long b) 6 { 7 return b ? gcd(b, a%b) : a; 8 } 9 10 int main() 11 { 12 int T_T, t_t; 13 scanf("%d", &T_T); 14 for (t_t = 1; t_t <= T_T; ++t_t) { 15 scanf("%I64d%I64d%I64d%I64d%I64d", &n, &s1, &v1, &s2, &v2); 16 if (v1*s2 < v2*s1) { 17 std::swap(v1, v2); 18 std::swap(s1, s2); 19 } 20 long long max_cnt = std::min(n/s2, s1/gcd(s1, s2)); 21 long long ans = 0; 22 for (long long i = 0; i <= max_cnt; ++i) 23 ans = std::max(ans, i * v2 + (n-i*s2)/s1*v1); 24 printf("Case #%d: %I64d\n", t_t, ans); 25 } 26 }
标签:
原文地址:http://www.cnblogs.com/takeoffyoung/p/4937540.html