简单枚举+巧妙躲避大枚举量
#include<bits/stdc++.h> using namespace std; long long n,s1,v1,s2,v2,total; int main() { ios::sync_with_stdio(false); long long T,maxn=0; cin>>T; while(T--) { cin>>n>>s1>>v1>>s2>>v2; total=0; long long kase=0,money=0; long long q1=n/s1,q2=n/s2,q3=max(s1,s2); long long mincomplex=min(min(q1,q2),q3); if(mincomplex==q1) { for(long long i=0;i<=q1;i++){ kase=n-i*s1; money=i*v1+(kase/s2)*v2; if(money>=total) total=money; } } else if(mincomplex==q2) { for(long long i=0;i<=q2;i++){ kase=n-i*s2; money=i*v2+(kase/s1)*v1; if(money>=total) total=money; } } else { if(s2*v1>s1*v2) { for(long long i=0;i<=s1-1;i++){ kase=n-i*s2; money=i*v2+(kase/s1)*v1; if(money>=total) total=money; } } else { for(long long i=0;i<=s2-1;i++) { kase=n-i*s1; money=i*v1+(kase/s2)*v2; if(money>=total) total=money; } } } cout<<"Case #"<<++maxn<<": "<<total<<"\n"; } return 0; }
12325 - Zombie's Treasure Chest.
时间: 2024-10-12 15:41:37