hdu---(4310)Hero(贪心算法)

Hero

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2606    Accepted Submission(s): 1169

Problem Description

When
playing DotA with god-like rivals and pig-like team members, you have
to face an embarrassing situation: All your teammates are killed, and
you have to fight 1vN.

There are two key attributes for the
heroes in the game, health point (HP) and damage per shot (DPS). Your
hero has almost infinite HP, but only 1 DPS.

To simplify the
problem, we assume the game is turn-based, but not real-time. In each
round, you can choose one enemy hero to attack, and his HP will decrease
by 1. While at the same time, all the lived enemy heroes will attack
you, and your HP will decrease by the sum of their DPS. If one hero‘s HP
fall equal to (or below) zero, he will die after this round, and cannot
attack you in the following rounds.

Although your hero is undefeated, you want to choose best strategy to kill all the enemy heroes with minimum HP loss.

Input

The
first line of each test case contains the number of enemy heroes N (1
<= N <= 20). Then N lines followed, each contains two integers
DPSi and HPi, which are the DPS and HP for each hero. (1 <= DPSi, HPi
<= 1000)

Output

Output one line for each test, indicates the minimum HP loss.

Sample Input

1
10 2
2
100 1
1 100

Sample Output

20
201

Author

TJU

Source

2012 Multi-University Training Contest 2

代码:先是模拟,然后优化,之后得到这么一个jiahuo ....

 1 #include<cstring>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 struct node{
 6   int HP,DSP;
 7   bool operator < (const node & a)const{
 8       return DSP*a.HP>a.DSP*HP;
 9   }
10 };
11 node st[22];
12 int main(){
13
14   int n;
15   int ans;
16 // freopen("test.in","r",stdin);
17   while(scanf("%d",&n)!=EOF){
18       ans=0;
19      for(int i=0;i<n;i++){
20       scanf("%d%d",&st[i].HP,&st[i].DSP);
21      }
22      sort(st,st+n);
23      for(int i=0;i<n;i++){
24         for(int j=i;j<n;j++){
25              ans+=st[j].DSP*st[i].HP;
26        }
27      }
28    printf("%d\n",ans);
29   }
30 return 0;
31 }

时间: 2024-10-15 19:14:38

hdu---(4310)Hero(贪心算法)的相关文章

hdu 1052(田忌赛马 贪心算法,sort排序)

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18155    Accepted Submission(s): 5281 Problem Description Here is a famous story in Chinese history. "That was about

HDU - 4310 Hero(贪心)

题意:无限生命,一点攻击力,和敌人对A(敌人只有攻击力和生命这两个属性),如何安排打到敌人的次序使得自己损失的生命最少. 攻击力高的可能血条很长,攻击力一般的可能血条很短,要先把相对比率高的先杀掉. 样例:2 100 1 101 100 2 100 1 1 100 第一个样例:10301  第二个:201 1 //100 1 2 //101 100 3 #include <iostream> 4 #include <algorithm> 5 using namespace std;

hdu 4296 Buildings 贪心算法 今日首A 详细解析 ,有些数据类型最好用long long

Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2278    Accepted Submission(s): 870 Problem Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr

HDU 4950 Monster (贪心算法)

题目链接 题意:有一个怪物的血量为h,人攻击怪物,每回合可以杀掉a滴血,再回b滴血,k个回合之后人会休息一回合,即人不攻击而怪物回b滴血,问能否杀死.翻译过来就是给定一个数h,每轮可以先减a再加b,k轮后会有一轮只加b不减a,如果再这过程中存在h<=0就输出YES,否则输出NO. 题解:注意是先减a再加b,有可能不加b就已经h<=0,先分类讨论ab,如果a比b大那么只有可能第一回合杀死,一旦+b就不可能在杀死了,如果a比b小,讨论在经过k-1轮后第k轮只减不加能否<=0,再讨论k+1轮的

HDU 1009 FatMouse&#39; Trade (贪心算法)

题意:就是老鼠要用猫粮换粮食,第i个房间一些东西,要用东西去换,可以不全换.问给定的猫粮最多能换多少粮食. 析:贪心算法.我们先算出来每个房间物品的平均价格是多少,肯定越低越好,并且如果能全换就全换,如果不能, 肯定是最后一次了,就把剩下全部换了,看看能换多少.求和. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <v

HDU 1009.FatMouse&#39; Trade【贪心算法】【8月16】

FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and req

hdu 1050(贪心算法)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19278    Accepted Submission(s): 6582 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

hdu 1789 Doing HomeWork Again (贪心算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1789 /*Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7903 Accepted Submission(s): 4680 Problem Description Ignatius has just c

hdu 4040 (贪心算法)

这题是我们学校比赛的题目,因为当时参加精英组比赛,除了3个大二的其他都是大三大四的大神,就抱着打酱油的心态去了,结果真的打酱油了; 事后看看题目,确实有些题目以当前水平是可以做出来的,原因应该是 心态 以及 时间分配上的问题. 这题一直卡在题目什么意思上,还有一题 求前K大数的,那题最后想到用堆,但是不会写- -,忘了优先队列这个东西.所以很遗憾啊.. 总而言之就是会的东西太少了哈...还需要好好加油; 这题的意思就是说每个细胞每秒只能产生一个噬菌体,无论这个细胞里面有多少噬菌体,然后攒齐一定数