hdoj3979Monster【贪心】
来源:互联网 发布:linux管道 文件 编辑:程序博客网 时间:2024/06/07 20:18
Monster
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1707 Accepted Submission(s): 463
Problem Description
One day, v11 encounters a group of monsters in a foreast. In order to defend the homeland, V11 picks up his weapon and fights!
All the monsters attack v11 at the same time. Every enemy has its HP, and attack value ATK. In this problem, v11 has his ATK and infinite HP. The damage (also means reduction for HP) is exactly the ATK the attacker has. For example, if v11's ATK is 13 and the monster's HP is 27, then after v11's attack, the monster's HP become 27 - 13 = 14 and vice versa.
v11 and the monsters attack each other at the same time and they could only attack one time per second. When the monster's HP is less or equal to 0 , we think this monster was killed, and obviously it would not attack any more. For example, v11's ATK is 10 and a monster's HP is 5, v11 attacks and then the monster is killed! However, a monster whose HP is 15 will be killed after v11 attack for two times. v11 will never stop until all the monsters are killed ! He wants to minimum the HP reduction for the fight! Please note that if in some second, some monster will soon be killed , the monster's attack will works too.
All the monsters attack v11 at the same time. Every enemy has its HP, and attack value ATK. In this problem, v11 has his ATK and infinite HP. The damage (also means reduction for HP) is exactly the ATK the attacker has. For example, if v11's ATK is 13 and the monster's HP is 27, then after v11's attack, the monster's HP become 27 - 13 = 14 and vice versa.
v11 and the monsters attack each other at the same time and they could only attack one time per second. When the monster's HP is less or equal to 0 , we think this monster was killed, and obviously it would not attack any more. For example, v11's ATK is 10 and a monster's HP is 5, v11 attacks and then the monster is killed! However, a monster whose HP is 15 will be killed after v11 attack for two times. v11 will never stop until all the monsters are killed ! He wants to minimum the HP reduction for the fight! Please note that if in some second, some monster will soon be killed , the monster's attack will works too.
Input
The first line is one integer T indicates the number of the test cases. (T <=100)
Then for each case, The first line have two integers n (0<n<=10000), m (0<m<=100), indicates the number of the monsters and v11's ATK . The next n lines, each line has two integers hp (0<hp<=20), g(0<g<=1000) ,indicates the monster's HP and ATK.
Then for each case, The first line have two integers n (0<n<=10000), m (0<m<=100), indicates the number of the monsters and v11's ATK . The next n lines, each line has two integers hp (0<hp<=20), g(0<g<=1000) ,indicates the monster's HP and ATK.
Output
Output one line.
First output “Case #idx: ”, here idx is the case number count from 1. Then output the minimum HP reduction for v11 if he arrange his attack order optimal .
First output “Case #idx: ”, here idx is the case number count from 1. Then output the minimum HP reduction for v11 if he arrange his attack order optimal .
Sample Input
2 3 1 1 10 1 20 1 40 1 10 7 3
Sample Output
Case #1: 110 Case #2: 3
Author
v11
Source
2011 Multi-University Training Contest 14 - Host by FZU
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;struct Node{ int hp,atk; double r;}A[10010];bool cmp(Node a,Node b){ return a.r>b.r;}int main(){ int t,i,j,k=1,n,m; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); int sum=0,sec; long long ans=0; for(i=0;i<n;++i){ scanf("%d%d",&A[i].hp,&A[i].atk); if(A[i].hp%m){ sec=A[i].hp/m+1; } else { sec=A[i].hp/m; } A[i].r=1.0*A[i].atk/(1.0*sec); sum+=A[i].atk; } sort(A,A+n,cmp); for(i=0;i<n;++i){ while(A[i].hp>0){ ans+=sum; A[i].hp-=m; } sum-=A[i].atk; } printf("Case #%d: %lld\n",k++,ans); } return 0;}
0 0
- hdoj3979Monster【贪心】
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- Subversion Edge安装
- 鸟哥的Linux私房菜(基础篇)- 第二十章、启动流程、模块管理与 Loader
- hdu 1587
- Java的悲观锁与乐观锁
- IOS AssetsLibrary框架的使用
- hdoj3979Monster【贪心】
- vs_start vs_end详解
- class_getInstanceMethod和class_getClassMethod
- 为什么选择 Java 8 ?
- utf8字符串截取
- lightoj 1078 - Integer Divisibility 【同余】
- 鸟哥的Linux私房菜(基础篇)- 第二十一章、系统配置工具(网络与打印机)与硬件侦测
- 我的杂谈
- extjs 里执行多行选中,和单行选中的操作