hdu 4091

#include<stdio.h>
#include<math.h>
__int64 gcd(__int64 a,__int64 b) {
 if(b==0)
  return a;
 else
  gcd(b,a%b);
}
__int64 lcm(__int64 a,__int64 b) {
 __int64 t;
 if(a<b) {
  t=a;
  a=b;
  b=t;
 }
 return a/gcd(a,b)*b;
}
int main() {
 __int64 t,n,s1,v1,s2,v2,ans,i,d,l,m,j=0;
 scanf("%I64d",&d);
 while(d--) {
  scanf("%I64d%I64d%I64d%I64d%I64d",&n,&s1,&v1,&s2,&v2);
         l=lcm(s1,s2);
       m=n%l;
    i=n/l;
    if(i) {
     i--;m+=l;
    }
    i=i*l;
    double k1,k2;
    k1=1.0*v1/s1;
    k2=1.0*v2/s2;
    if(k1>=k2)
     ans=i/s1*v1;
    else
     ans=i/s2*v2;
    if(s1<s2) {
     t=s1;
     s1=s2;
     s2=t;
     t=v1;
     v1=v2;
     v2=t;
    }
    __int64 max=0;
    for(i=0;i*s1<=m;i++) {
     t=i*v1+(m-i*s1)/s2*v2;
     if(t>max)
      max=t;
    }
    printf("Case #%I64d: %I64d ",++j,max+ans);
    }
 return 0;
}
原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410997.html