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)可以减少 ...
随机推荐
- PN结讲解
可能大家在使用半导体器件的时候只是在使用它的电气属性,并没有很好的关心下它是什么原因才有了这样的电气属性,那么我们本篇就从物理结构分析下PN结吧. 首先看一张比较陈旧的图图: (就按自己的笔记简单谈谈 ...
- C++ tinyXML的使用和字符编码转换
转载:http://jetyi.blog.51cto.com/1460128/761708/ 关于tinyxml使用的文档有很多(这篇文章就写的很好),这里仅提一下字符编码的转换问题,如果你不熟悉字符 ...
- JQuery使用教程
jQuery简介 jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team jQuery是对原生JavaScript二次封装的工具函数集合 ...
- vim的加密和解密?
vim中出现的错误提示含义: 参考: http://blog.csdn.net/u014599371/article/details/43955169 E488: trailing character ...
- bootstrap的 附加导航Affix导航 (侧边窄条式 滚动监控式导航) 附加导航使用3.
affix: 意思是粘附, 附着, 沾上. 因此, 附加导航就是 bootstrap的 Affix.js组件. bootstrap的 附加导航, 不是说导航分成主导航, 或者什么 副导航的 而是指, ...
- json字符窜转对象
第一种方法: 注意引用:using System.Runtime.Serialization.Json; using System.IO; static void Main(string[] args ...
- 为什么mongo中不能用int作为key
为什么mongo中不能用int作为key??
- python ros 回充调用demo
#!/usr/bin/env python #coding=utf- import rospy from std_msgs.msg import String def talker(): pub = ...
- ros pbstream
https://blog.csdn.net/xiekaikaibing/article/details/80320822
- vue饿了么学习笔记(1)vue-cli开启项目
一.vue-cli介绍 vue-cli是vue的脚手架工具 ----> 帮助写好vue.js基础代码的工具: ① 搭建目录结构 ② 进行本地调试 ③ 进行代码部署 ④ 热加载 ⑤ 进行单元测试 ...