G - Zombie’s Treasure Chest(动态规划专项)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle lasts from morning to night and the warriors find the zombies are undead and invincible.
Of course, the treasures should not be left here. Unfortunately, the warriors cannot carry all the treasures by the treasure chest due to the limitation of the capacity of the chest. Indeed, there are only two types of treasures: emerald and sapphire. All of the emeralds are equal in size and value, and with infinite quantities. So are sapphires.
Being the priest of the warriors with the magic artifact: computer, and given the size of the chest, the value and size of each types of gem, you should compute the maximum value of treasures our warriors could bring back.
Input
Output
Sample Input
Sample Output
2.求S1,S2的最小公倍数LCM
3.求商s=N/LCM,余数y=N%LCM
4.s>=1 则s--,y+=LCM
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue> using namespace std; long long gcd(long long a,long long b)
{
if(b==) return a;
return gcd(b,a%b);
} int main()
{
freopen("1.txt","r",stdin);
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=;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=;
}
mx=;
for(i=,j=;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 ;
}
G - Zombie’s Treasure Chest(动态规划专项)的更多相关文章
- 一道看似dp实则暴力的题 Zombie's Treasure Chest
Zombie's Treasure Chest 本题题意:有一个给定容量的大箱子,此箱子只能装蓝宝石和绿宝石,假设蓝绿宝石的数量无限,给定蓝绿宝石的大小和价值,要求是获得最大的价值 题解:本题看似是 ...
- HDU 4091 Zombie’s Treasure Chest 分析 难度:1
Zombie’s Treasure Chest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- UVa 12325 - Zombie's Treasure Chest-[分类枚举]
12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and fi ...
- hdu 4091 Zombie’s Treasure Chest 贪心+枚举
转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝 ...
- BZOJ2490 Zombie’s Treasure Chest
如果n = lcm(s1, s2),那么就可以直接得到maxV = (v / s1 * v1, v / s2 *v2) 然后还剩下一点体积我们暴力枚举用s1的量,让s1为max(s1, s2)可以减少 ...
- UVa 12325 Zombie's Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
- hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4091 /** 这题的一种思路就是枚举了: 基于这样一个事实:求出lcm = lcm(s1,s2), n ...
- UVa12325, Zombie's Treasure Chest
反正书上讲的把我搞得晕头转向的,本来就困,越敲越晕...... 转网上一个大神写的吧,他分析的很好(个人感觉比书上的清楚多了) 转:http://blog.csdn.net/u010536683/ar ...
- uva 12325 Zombie's Treasure Chest
https://vjudge.net/problem/UVA-12325 题意: 一个箱子,体积为N 两种宝物,体积为S1.S2,价值为V1.V2,数量无限 最多装多少价值的宝物 数据范围:2^32 ...
随机推荐
- 我是如何给discuz模板做语法高亮的
本人一直做ASP.NET开发,近期接到任务要用Discuz开发一个社区,第一次接触PHP,PHP灵活的语法,天生的模块化,各种语法糖深深的震惊了我,我从内心深处感受到了PHP是最牛逼的语言!!! 好了 ...
- Unity3D脚本使用:Random
实例: 为集合变量赋值,并运行,点击按钮,运行结果如图
- BestCoder 百度之星2016
20160523 百度之星初赛第一场 1001 All X Problem Description F(x, m)F(x,m) 代表一个全是由数字xx组成的mm位数字.请计算,以下式子是否成立: F( ...
- 页面导入样式时,使用link和@import有什么区别?
1 link属于XHTML标签,而@import是CSS提供的: 2 页面被加载的时,link会同时被加载,而@import引用的CSS会等到页面被加载完再加载: 3 import只有在IE5以上才能 ...
- EF Codefirst 初步学习(二)—— 程序管理命令 更新数据库
前提:搭建成功codefirst相关代码,参见EF Codefirst 初步学习(一)--设置codefirst开发模式 具体需要注意点如下: 1.确保实体类库程序生成成功 2.确保实体表类库不缺少 ...
- Homestead 使用总结
homestead Laravel Homestead是一个官方预封装的Vagrant"箱子" 内置 Nginx.PHP 5.6.MySQL.Postgres.Redis.Memc ...
- 关于PC端与手机端随着手指移动图片位置放生变化的拖拽事件
当按下鼠标时,图片随鼠标移动松开时图片回到原位 drag("div_id") function drag(node_id){ var node = document.getElem ...
- 为什么要html语义化?
1.什么是HTML语义化? <基本上都是围绕着几个主要的标签,像标题(H1~H6).列表(li).强调(strong em)等等> 根据内容的结构化(内容语义化),选择合适的标签(代码语义 ...
- WinSpy涉及的windows api
WinSpy涉及的windows api WinSpy是仿造微软Spy++的开源项目,但只涉及Spy++的窗口句柄.窗口的属性.styles.类名子窗口.进程线程信息等查找功能.功能虽然不算强大,但涉 ...
- 导航栏底部黑线隐藏 UINavigationBar hidden Bottom Line
3种方法: 1.大杀器 ,iOS 10.2 最新系统亲测无问题( 添加导航栏分类) https://github.com/samwize/UINavigationBar-Addition/ 2.io ...