您的位置:首页 > 其它

HDU 4091 - Zombie’s Treasure Chest

2012-11-04 19:08 281 查看
地址: http://acm.hdu.edu.cn/showproblem.php?pid=4091

先除去最小公倍数。

然后暴力枚举。

需要注意这种数据: 13 2 5 3 7

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>

using namespace std;

long long gcd(long long a,long long b)
{
if(b==0) return a;
return gcd(b,a%b);
}

int main()
{
int cas,t;
long long n,s1,v1,s2,v2;
long long g,l,res,rv1,rv2,i,mx,tmp,j;
cin>>t;
for(cas=1;cas<=t;cas++)
{
cin>>n>>s1>>v1>>s2>>v2;
if(s1>s2)
{
swap(s1,s2);
swap(v1,v2);
}
g=gcd(s1,s2);
l=s1/g*s2;
rv1=l/s1*v1;
rv2=l/s2*v2;
if(n>=l+l)
{
res=(n-l)/l*(rv1>rv2?rv1:rv2);
n=n%l+l;
}
else
{
res=0;
}
mx=0;
for(i=0,j=0;i<=n;i+=s2,j++)
{
tmp=j*v2+(n-i)/s1*v1;
if(tmp>mx)
{
mx=tmp;
}
}
res+=mx;
cout<<"Case #"<<cas<<": "<<res<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: