标签:des blog io os java ar strong for div
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4442 Accepted Submission(s): 889
#include <cstdio> #include <algorithm> #include <cmath> using namespace std; long long n,s1,v1,s2,v2; const double eps=1e-11; long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b); } long long lcm(long long a,long long b){ if(a*b==0)return 0; return a*b/(gcd(a,b)); } int main(){ int T; scanf("%d",&T); for(int ca=1;ca<=T;ca++){ scanf("%I64d%I64d%I64d%I64d%I64d",&n,&s1,&v1,&s2,&v2); if(s1>s2){ swap(s1,s2);swap(v1,v2); } long long LCM=lcm(s1,s2); long long t1=n>LCM?(n-LCM)/LCM:0; n-=t1*LCM; long long ans=(n/s1)*v1+((n%s1)/s2)*v2; long long a=n/s2; for(long long i=0;i<=a;i++){ long long tmp=(i*v2)+((n-i*s2)/s1)*v1; ans=max(ans,tmp); } ans+=t1*max((LCM/s1)*v1,(LCM/s2)*v2); printf("Case #%d: %I64d\n",ca,ans); } return 0; }
hdu4091 Zombie’s Treasure Chest
标签:des blog io os java ar strong for div
原文地址:http://www.cnblogs.com/xuesu/p/3978954.html