HDU 4091 Zombie’s Treasure Chest 分析 难度:1
Zombie’s Treasure Chest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4442 Accepted Submission(s): 889
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.
100 1 1 2 2
100 34 34 5 3
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long n,s1,v1,s2,v2;
const double eps=1e-11;
long long gcd(long long a,long long b){
return b==0?a:gcd(b,a%b);
}
long long lcm(long long a,long long b){
if(a*b==0)return 0;
return a*b/(gcd(a,b));
}
int main(){
int T;
scanf("%d",&T);
for(int ca=1;ca<=T;ca++){
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&s1,&v1,&s2,&v2);
if(s1>s2){
swap(s1,s2);swap(v1,v2);
}
long long LCM=lcm(s1,s2);
long long t1=n>LCM?(n-LCM)/LCM:0;
n-=t1*LCM;
long long ans=(n/s1)*v1+((n%s1)/s2)*v2;
long long a=n/s2;
for(long long i=0;i<=a;i++){
long long tmp=(i*v2)+((n-i*s2)/s1)*v1;
ans=max(ans,tmp);
}
ans+=t1*max((LCM/s1)*v1,(LCM/s2)*v2);
printf("Case #%d: %I64d\n",ca,ans);
}
return 0;
}
HDU 4091 Zombie’s Treasure Chest 分析 难度:1的更多相关文章
- hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4091 /** 这题的一种思路就是枚举了: 基于这样一个事实:求出lcm = lcm(s1,s2), n ...
- hdu 4091 Zombie’s Treasure Chest 贪心+枚举
转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝 ...
- G - Zombie’s Treasure Chest(动态规划专项)
G - Zombie’s Treasure Chest Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- 一道看似dp实则暴力的题 Zombie's Treasure Chest
Zombie's Treasure Chest 本题题意:有一个给定容量的大箱子,此箱子只能装蓝宝石和绿宝石,假设蓝绿宝石的数量无限,给定蓝绿宝石的大小和价值,要求是获得最大的价值 题解:本题看似是 ...
- 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 ...
- UVa12325, Zombie's Treasure Chest
反正书上讲的把我搞得晕头转向的,本来就困,越敲越晕...... 转网上一个大神写的吧,他分析的很好(个人感觉比书上的清楚多了) 转:http://blog.csdn.net/u010536683/ar ...
- Uva 12325 Zombie's Treasure Chest (贪心,分类讨论)
题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...
- UVA - 12325 Zombie's Treasure Chest (分类搜索)
题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...
- BZOJ2490 Zombie’s Treasure Chest
如果n = lcm(s1, s2),那么就可以直接得到maxV = (v / s1 * v1, v / s2 *v2) 然后还剩下一点体积我们暴力枚举用s1的量,让s1为max(s1, s2)可以减少 ...
随机推荐
- DDR2是什么意思
DDR2DDR2(Double Data Rate 2) SDRAM是由JEDEC(电子设备工程联合委员会)进行开发的新生代内存技术标准,它与上一代DDR内存技术标准最大的不同就是,虽然同是采用了在时 ...
- Windows Services 学习(转载)
转载:http://blog.csdn.net/fakine/article/details/42107571 一.学习点滴 1.本机服务查看:services.msc /s2.服务手动安装(使用sc ...
- 函数引用参数加const
Fun(const Type& type); 在引用传递的时候,在函数内部改变参数,会改变参数实际值. 加上了const就不能被修改.
- linux提示usb_serial_generic_write_bulk_callback - urb stoped: -32
1.环境: 上位机:ubuntu16.04 Linux jello 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_ ...
- hdu 6406 Taotao Picks Apples 线段树 单点更新
Taotao Picks Apples Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Ot ...
- 谈谈java中的final关键字
知识点:final(最终的)关键字修饰类.方法.属性 1.final修饰类:那么这个就无法被继承,如String类.StringBuffer类.System类 2.final修饰方法:被修饰的方法不能 ...
- 软件设计师真题试题&&答案
软件设计师2013上半年上午试题及答案详解 下午试题 2013下半年上午答案 试题 下午答案 试题 2014上半年上午答案 2015上半年上午答案 2016上半年上午试题
- React native 的DatePickerIOS组件
1.首先如代码所示 引入DatePickerIOS组件 设置他的时间是当前时间 export default class AlertDemo extends Component { render() ...
- Intel微处理器学习笔记(四) 内存分页
内存分页机制(memory paging mechanism)是从386开始的.线性地址通过分页机制透明转换为物理地址. 从这里知道:1. 如果不分页,则线性地址等于物理地址:2. 如果分页,则线性地 ...
- gcc 编译出现 internal compiler error: Killed
系统没有交换分区, 编译过程中内存耗尽, 导致了编译中断 …解决方式也很简单, 就是增加一个交换分区: 创建分区文件, 大小 2G dd if=/dev/zero of=/swapfile ...