如果n = lcm(s1, s2),那么就可以直接得到maxV = (v / s1 * v1, v / s2 *v2)

然后还剩下一点体积我们暴力枚举用s1的量,让s1为max(s1, s2)可以减少枚举次数。。。然后就做完了QAQ

 

 1 /**************************************************************
 2     Problem: 2490
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:4 ms
 7     Memory:804 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <algorithm>
12  
13 using namespace std;
14 typedef long long ll;
15  
16 ll v, s1, s2, v1, v2;
17 ll ans, del;
18  
19 int main() {
20     int T, icase, i;
21     ll t, tmp;
22     scanf("%d", &T);
23     for (icase = 1; icase <= T; ++icase) {
24         scanf("%lld%lld%lld%lld%lld", &v, &s1, &v1, &s2, &v2);
25         if (s1 < s2) swap(s1, s2), swap(v1, v2);
26         tmp = s1 * s2 / __gcd(s1, s2), t = v / tmp;
27         v = v % tmp;
28         if (t) --t, v += tmp;
29         ans = max(t * (tmp / s1) * v1, t * (tmp / s2) * v2);
30         for (i = del = 0; i <= v / s1; ++i)
31             del = max(del, i * v1 + (v - i * s1) / s2 * v2);
32         printf("Case #%d: %lld\n", icase, ans + del);
33     }
34     return 0;
35 }
View Code

 

posted on 2015-03-23 20:03  Xs酱~  阅读(224)  评论(0编辑  收藏  举报