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
先除去最小公倍数。
然后暴力枚举。
需要注意这种数据: 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; }
相关文章推荐
- hdu_4091_Zombie’s Treasure Chest(贪心+枚举)
- HDU—— 4091 Zombie’s Treasure Chest
- hdu(4091)Zombie’s Treasure Chest(贪心+背包)
- HDU 4091 Zombie’s Treasure Chest(2011ACM上海赛区预选赛第一题)
- hdu 4091 Zombie’s Treasure Chest
- hdu 4091 Zombie’s Treasure Chest 贪心+枚举
- hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)
- HDU 4091 Zombie’s Treasure Chest (数学加暴力)
- HDU 4091 【2011上海现场赛 A】 Zombie’s Treasure Chest
- hdu 4091 Zombie’s Treasure Chest 贪心+枚举
- hdu 4091 Zombie’s Treasure Chest
- HDU_4091_Zombie’s Treasure Chest_最小公倍数、机智地枚举
- HDU-4091 Zombie’s Treasure Chest
- HDU 4091--Zombie’s Treasure Chest
- HDU 4091 Zombie’s Treasure Chest(贪心+枚举)
- HDU 4091 Zombie’s Treasure Chest (不错的数论题)
- HDU 4091 Zombie’s Treasure Chest 分析 难度:1
- hdu 4091 Zombie’s Treasure Chest【2011 ACM Asia Shanghai Regional Problem A】
- 解题报告(三):Zombie’s Treasure Chest 上海现场赛A题(hdu 4091)
- hdu 4091 Zombie’s Treasure Ches 贪心