博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3979 Monster (贪心排序)
阅读量:6229 次
发布时间:2019-06-21

本文共 3012 字,大约阅读时间需要 10 分钟。

Monster

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1383    Accepted Submission(s): 363

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.
 

 

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.
 

 

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 .
 

 

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
 

 

排序一下就解决了,注意用long long 就可以了。

 

1 /* *********************************************** 2 Author        :kuangbin 3 Created Time  :2013-11-17 21:24:55 4 File Name     :E:\2013ACM\比赛练习\2013-11-17\G.cpp 5 ************************************************ */ 6  7 #include 
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 using namespace std;20 21 struct Node22 {23 int h,g;24 }node[10010];25 int n,m;26 bool cmp(Node a,Node b)27 {28 return a.h*b.g < b.h*a.g;29 }30 int main()31 {32 //freopen("in.txt","r",stdin);33 //freopen("out.txt","w",stdout);34 int T;35 int iCase = 0;36 scanf("%d",&T);37 while(T--)38 {39 iCase ++;40 scanf("%d%d",&n,&m);41 for(int i = 0;i < n;i++)42 {43 scanf("%d%d",&node[i].h,&node[i].g);44 node[i].h = (node[i].h + m - 1)/m;45 }46 sort(node,node+n,cmp);47 long long ans = 0;48 int cnt = 0;49 for(int i = 0;i < n;i++)50 {51 cnt += node[i].h;52 ans += (long long)cnt*node[i].g;53 }54 printf("Case #%d: %I64d\n",iCase,ans);55 }56 return 0;57 }

 

 

 

 

 

转载地址:http://ygtna.baihongyu.com/

你可能感兴趣的文章
apache服务器日志分析程序webalizer
查看>>
Trunk实现不同VLAN之间 相同网段的互通
查看>>
(版本定制)第8课:Spark Streaming源码解读之RDD生成生命周期彻底研究和思考
查看>>
为底层元素注册监听器
查看>>
ZeroTurnaround(做 JRebel 的公司)关于 Java 类动态重载的一系列文章
查看>>
awk级sed处理下一行
查看>>
windows中如何查看本机的MAC地址和主机名
查看>>
Javascript 中的上下文
查看>>
raid 相关收集
查看>>
选购邮件系统五大指标看U-Mail对比国际大牌
查看>>
3. JDK Map
查看>>
eclipse下avd无法启动解决办法
查看>>
《HTML与CSS知识》系列分享专栏
查看>>
vcpkg win10下编译zlib失败
查看>>
SIP协议解析
查看>>
windows7&8下安装变色龙到隐藏分区的方法
查看>>
系统找不到指定的文件 C:\WINDOWS\system32\<LANG_NAME>\mstsc.exe.MUI
查看>>
解决hal.dll丢失问题 调试方法启动XP
查看>>
The CVS Client/Server Protocol
查看>>
NSDateFormatter 真机调试
查看>>