HDU 3979 Monster (贪心排序)
Monster
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1383 Accepted Submission(s): 363
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.
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.
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 .
3 1
1 10
1 20
1 40
1 10
7 3
Case #2: 3
排序一下就解决了,注意用long long 就可以了。
/* ***********************************************
Author :kuangbin
Created Time :2013-11-17 21:24:55
File Name :E:\2013ACM\比赛练习\2013-11-17\G.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; struct Node
{
int h,g;
}node[];
int n,m;
bool cmp(Node a,Node b)
{
return a.h*b.g < b.h*a.g;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int iCase = ;
scanf("%d",&T);
while(T--)
{
iCase ++;
scanf("%d%d",&n,&m);
for(int i = ;i < n;i++)
{
scanf("%d%d",&node[i].h,&node[i].g);
node[i].h = (node[i].h + m - )/m;
}
sort(node,node+n,cmp);
long long ans = ;
int cnt = ;
for(int i = ;i < n;i++)
{
cnt += node[i].h;
ans += (long long)cnt*node[i].g;
}
printf("Case #%d: %I64d\n",iCase,ans);
}
return ;
}
HDU 3979 Monster (贪心排序)的更多相关文章
- HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场
题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- HDU.2647 Reward(拓扑排序 TopSort)
HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的 ...
- HDU 4950 Monster(公式)
HDU 4950 Monster 题目链接 题意:给定怪兽血量h,你攻击力a.怪物回血力b,你攻击k次要歇息一次,问是否能杀死怪兽 思路:签到题,注意最后一下假设打死了怪,那么怪就不会回血了 思路: ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 4442 Physical Examination(关于贪心排序)
这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...
- hdu 4442 Physical Examination 贪心排序
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- 第10月第28天 touchesBegan hittest
1. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touchesBe ...
- 洛谷 P1006 传纸条 多维DP
传纸条详解: 蒟蒻最近接到了练习DP的通知,于是跑来试炼场看看:发现有点难(毕竟是蒟蒻吗)便去翻了翻题解,可怎么都看不懂.为什么呢?蒟蒻发现题解里都非常详细的讲了转移方程,讲了降维优化,但这题新颖之处 ...
- python垃圾回收二
由于循环引用的存在,我们在删除了a跟b之后,引用计数是1,这样,现有的垃圾回收机制是永远不可能把她们删除了.他们将永远存在于内存中. 我们当然不能对这种情况置之不理,于是,我们又添加了两种新的回收机制 ...
- 【腾讯云】自己搭建的腾讯云服务器JavaEE环境
0.安装SSH登录 1.生成公钥对 ssh-keygen -t rsa -P '' -P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车.它在/home/ch ...
- 在Windows环境中利用Responder工具窃取NTLMv2哈希
在Windows环境中利用Responder工具窃取NTLMv2哈希 翻译自:https://github.com/incredibleindishell/Windows-AD-environment ...
- SQL Server限制IP访问1433端口
1.用系统自带的防火墙,启用防火墙 2.点击[添加端口],名称填1433,端口号填1433 3.协议TCP,点[更改范围],选自定义列表,那个框里就填本机服务器的IP地址.
- 安装Python3.6.4后,在使用numpy时报错RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
原因: 因为安装numpy用的是 pip来安装的 pypi官方对于numpy的库已经升级了,但是升级后的版本与其他的库不匹配 所以报错 解决: 先把已经安装的numpy卸载: pip uninstal ...
- conda管理python包
参考:http://blog.sina.com.cn/s/blog_c3c116470102wlv5.html 查看python,numpy,scipy,matplotlib的版本及安装位置: htt ...
- Coursera台大机器学习技法课程笔记15-Matrix Factorization
很多ML模型用的都是数值特征,那么对于分类特征,该怎么做呢? 以linear network为例:先对特征进行转换,转换成有意义的特征后,再对其进行线性组合 进一步,模型可表示为:使Ein最小,我们就 ...
- Linux 下crontab 详解转
http://yaksayoo.blog.51cto.com/510938/162062 Linux计划任务工具cron用法详解 linux下大名鼎鼎的计划任务工具crontab的使用介绍baidu. ...