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 就可以了。

 /* ***********************************************
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 (贪心排序)的更多相关文章

  1. HDU 5821 Ball (贪心排序) -2016杭电多校联合第8场

    题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题 ...

  2. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  3. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  4. HDU.2647 Reward(拓扑排序 TopSort)

    HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的 ...

  5. HDU 4950 Monster(公式)

    HDU 4950 Monster 题目链接 题意:给定怪兽血量h,你攻击力a.怪物回血力b,你攻击k次要歇息一次,问是否能杀死怪兽 思路:签到题,注意最后一下假设打死了怪,那么怪就不会回血了 思路: ...

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

  7. HDU 6034 Balala Power!(贪心+排序)

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. HDU 4442 Physical Examination(关于贪心排序)

    这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...

  9. hdu 4442 Physical Examination 贪心排序

    Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. JD m站自我解析理解

    第一步:从首页着手 文档部分:应用的是H5默认文档开头 即:<!DOCUMENT html> head部分:放了一些相关的JS,title描述,然后就是meta表述了.比较有参考的如下 & ...

  2. java中final、finally、finalized使用方法

    首先需要明白  final和finally是关键字,finalize是一个方法. 1. final关键字 final可以修饰类.方法.变量, 修饰类表示类不可以被继承 修饰方法表示此方法不可以被重写( ...

  3. 高可用的并行MySQL数据同步及分布式

    首先聊聊MySQL的数据分布式,目前最为常用的就是Replication(复制)技术.基于此技术外延开来有很多中架构,分类归结为如下:      1.树状结构(Master,Backup-Master ...

  4. Visual Studio 2012“完美的拥抱”Visual Studio Online

    看了Visual Studio 2012完美的拥抱GitHub 写的不错,不过,配置起来太麻烦.既然是使用VS编码,微软的东西嘛,当然还有更简单的,那就是Visual Studio Online.不用 ...

  5. Axure RP Pro 7.0

    Axure RP Pro专为Rapid Prototype Design而生,它可以辅助产品经理快速设计完整的产品原型,并结合批注.说明以及流程图.框架图等元素将产品完整地表述给各方面设计人员,如UI ...

  6. python基础-pthon

    1)python 由Guido开发 2)编译(compile)型:通过编译器把代码直接生成一个可执行文件. 比如把英语书一次性翻译成中文书.语言有:c,C++等 解释型:边编译边执行.语言如:java ...

  7. pixel像素基础

    地址:http://www.imooc.com/video/9564 dp(安卓),pt(iphone)是物理像素 ppi是由物理像素确定的 一英寸内有多少个像素渲染,ppi越高,图片越清晰 1px ...

  8. mybatis-config.xml 模板

    ssm模板 <?xml version="1.0" encoding="UTF-8" ?>  <!DOCTYPE configuration  ...

  9. activiti主要组件解析

    Activiti内部实现中,各主要部件关系 对外,提供Service服务,它是无状态的. 这些Service包括: protected RepositoryService repositoryServ ...

  10. InnoDB Lock浅谈

    数据库使用锁是为了支持更好的并发,提供数据的完整性和一致性.InnoDB是一个支持行锁的存储引擎,锁的类型有:共享锁(S).排他锁(X).意向共享(IS).意向排他(IX).为了提供更好的并发,Inn ...