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 ...
随机推荐
- PIE 阻断回溯——Cut
PIE(Prolog Inference Engine)通常是搜索所有的解.举个例子, 当然dialog窗口中一开始调用 run. 只会显示一个解(虽然事实上会得到两个解),在前面加上 X=1,就可以 ...
- UserDefault数据读取
//GameScene.h #include "cocos2d.h" USING_NS_CC; class GameScene : public cocos2d::Layer{pu ...
- [kuangbin带你飞]专题六 最小生成树 POJ 1287 Networking
最小生成树模板题 跑一次kruskal就可以了 /* *********************************************** Author :Sun Yuefeng Creat ...
- Silverlight 中MatrixTransform和其他Transform的数值转换
对各种transform的讲解已经很多了,但是有时MatrixTransform和其他transform变换效果之间需要转换时,变换量的转换又如何呢?下面的类就完成了Matrix和其他transfor ...
- Android服务
开启服务 (startservice) 服务一旦开启与调用者没有任何的关系 , 调用着的activity 即便是退出了 也不会影响 后台的service的运行. 在activity里面 不能去调用服务 ...
- win8,win10安装mysql
以管理员身份进到命令窗口后,找到要安装的文件,执行msiexec /package mysql-installer-community-5.7.16.0.msi 回车即可
- java中|与||有什么区别?那么&与&&呢
||当左边为真时,就不运行右边的表达式了|当左边为真,还是会运算右边的表达式&&当左边为假时,就不会运算右边的表达式&当左边为假时,还是会运算右边的表达式
- Springmvc+Myabtis+Ajax实现异步分页emp+dept(全部查询及模糊查询)
1.在项目中创建如下目录 2.创建实体类Dept package com.entity; import java.io.Serializable; /** * 部门表 * @author Admini ...
- wordpress建站过程5——footer.php
footer中写的就只有网站地图,公司信息等等简单东西而已: <?php wp_footer(); ?> <div class="footer"> < ...
- Failed to read candidate component class包冲突解决方法
该类问题出现错误有两个可能,第一JAR包错误,第二就是我们的System library版本不正确导致的问题.