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

Problem Description
  Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.
  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
  There are multiple test cases. The number of test cases T (T <= 200) is given in the first line of the input file. For each test case, there is only one line containing five integers N, S1, V1, S2, V2, denoting the size of the treasure chest is N and the size and value of an emerald is S1 and V1, size and value of a sapphire is S2, V2. All integers are positive and fit in 32-bit signed integers.
 
Output
  For each test case, output a single line containing the case number and the maximum total value of all items that the warriors can carry with the chest.
 
Sample Input
2
100 1 1 2 2
100 34 34 5 3
 
Sample Output
Case #1: 100
Case #2: 86
 
卡题在即使v1/s1>v2/s2且s2>s1
#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的更多相关文章

  1. hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4091 /** 这题的一种思路就是枚举了: 基于这样一个事实:求出lcm = lcm(s1,s2), n ...

  2. hdu 4091 Zombie’s Treasure Chest 贪心+枚举

    转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝 ...

  3. G - Zombie’s Treasure Chest(动态规划专项)

    G - Zombie’s Treasure Chest Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  4. 一道看似dp实则暴力的题 Zombie's Treasure Chest

     Zombie's Treasure Chest 本题题意:有一个给定容量的大箱子,此箱子只能装蓝宝石和绿宝石,假设蓝绿宝石的数量无限,给定蓝绿宝石的大小和价值,要求是获得最大的价值 题解:本题看似是 ...

  5. 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 ...

  6. UVa12325, Zombie's Treasure Chest

    反正书上讲的把我搞得晕头转向的,本来就困,越敲越晕...... 转网上一个大神写的吧,他分析的很好(个人感觉比书上的清楚多了) 转:http://blog.csdn.net/u010536683/ar ...

  7. Uva 12325 Zombie's Treasure Chest (贪心,分类讨论)

    题意: 你有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号的整数.你的任务是最多能装多少价值的宝物? 分析: 分类枚举, ...

  8. UVA - 12325 Zombie's Treasure Chest (分类搜索)

    题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...

  9. BZOJ2490 Zombie’s Treasure Chest

    如果n = lcm(s1, s2),那么就可以直接得到maxV = (v / s1 * v1, v / s2 *v2) 然后还剩下一点体积我们暴力枚举用s1的量,让s1为max(s1, s2)可以减少 ...

随机推荐

  1. 剑指Offer——跳台阶

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 思路分析 这个问题可以先从简单开始考虑,台阶只有1阶,只有1种跳法,台阶有2阶,有2种跳法:一种两 ...

  2. ZooKeeper参数调优

    zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为zoo.cfg.其中各配置项的含义,解释如下: 1.tickTime:Client-Serv ...

  3. Ubuntu 14.04 安装 qemu

    参考: Ubuntu 12.04之找不到Qemu命令 Ubuntu 14.04 安装 qemu 安装: sudo apt-get install qemu 使用ln命令建立软连接: sudo ln - ...

  4. UVa 11235 频繁出现的数值

    https://vjudge.net/problem/UVA-11235 题意: 给出一个非降序排列的整数数组a1,a2,...,an,你的任务是对于一系列询问(i,j),回答ai,ai+1,...a ...

  5. UVa 10723 电子人的基因(LCS)

    https://vjudge.net/problem/UVA-10723 题意: 输入两个A~Z组成的字符串,找一个最短的串,使得输入的两个串均是它的子序列,另外还需要统计长度最短的串的个数. 思路: ...

  6. 【Django】【待解决问题】

    1. from Crypto.Cipher import AES File "/Library/Frameworks/Python.framework/Versions/3.5/lib/py ...

  7. Cocos2d-x学习笔记(七)菜单

    菜单类继承关系如下: 图1 菜单类继承关系 文本菜单只能显示文本,包括:MenuItemLabel.MenuItemFont和MenuItemAtlasFont: #include "Hel ...

  8. C指针的一些知识

    原文:http://blog.csdn.net/soonfly/article/details/51131141 前言:复杂类型说明 要了解指针,多多少少会出现一些比较复杂的类型,所以我先介绍一下如何 ...

  9. WZY社区

    WZY社区是我自己做的一个网站,后面会详细更新,敬请关注!

  10. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...