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 ...
随机推荐
- 整理一些css在使用中的小技巧(进行中)
1. 消除li排列display:inline-block的间隙 ul{ font-size:; } ul li{ display:inline-block; }
- jdk之String
学习几个常用的String方法 1.concat /** * Concatenates the specified string to the end of this string. 连接指定的字符串 ...
- JDK根目录介绍
/bin 存放可执行程序(编译器javac.exe 运行器java.exe 文档生成器javadoc.exe等 ). /db 小型数据库文件. /jre JRE. /include 形成jdk的c. ...
- wpf xmal基础
1.名称空间的引用 比如想使用System.Windows.Controls名称空间 首先需要把改名称空间所在的程序集presentationFramework.dll引用到项目里 然后在根元素的起始 ...
- Zeppelin0.6.2使用hive解释器
Zeppelin0.6.2的jdbc Interpreter 配置 1.拷贝hive的配置文件hive-site.xml到zeppelin-0.6.2-bin-all/conf下. 2.进入conf下 ...
- out和ref之间的区别
首先:两者都是按引用传递的,使用后都将改变原来参数的数值. 其次:ref可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个数值从out传递进去的,out进去后,参数的数值为空,所 ...
- 关于在mfc中cstring转为float和ini
CString str1,str, str2; GetDlgItemText(IDC_EDIT1, str1); GetDlgItemText(IDC_EDIT2, str2); UINT value ...
- Openjudge-NOI题库-对齐输出
题目描述 Description 读入三个整数,按每个整数占8个字符的宽度,右对齐输出它们. 输入输出格式 Input/output 输入格式: 只有一行,包含三个整数,整数之间以一个空格分开. ...
- vim 撤销 恢复 快捷键
u 撤销上一步的操作 Ctrl+r 恢复上一步被撤销的操作
- MySQL数据库的数据备份和恢复(导入和导出)命令操作语法【转】
不管是Oracle数据库还是SQL Server数据库,每个数据库都有自己的一套数据备份和恢复的方法,MySQL数据库也不例外.MySQL数据库备份和恢复用到了两个命令,分别是“mysqldump”和 ...