HDU4310_Hero_贪心

Hero

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


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

大致题意:

回合制的DOTA。你有一个英雄,血量无限,攻击力为1。面对n个英雄,有各自的血量和攻击力。在每个回合,你可以攻击对方一个英雄一下,对方每个英雄攻击你一下。选择合适的攻击策略,当你把对方所有英雄打死时,你受到的伤害总和最小。


大体思路:

体会一下简单贪心的一般方法。

选择攻击顺序时,如果把相邻的两个英雄顺序调换,不会英雄前面和后面其他英雄对你的伤害,只会对他俩的伤害造成影响。

假设1英雄的攻击为A1,血量为H1;2英雄的分别为A2,H2。若先攻击1英雄,他俩造成的伤害为 A1H1+A2(H1+H2) ——式一 ;若先攻击2英雄,伤害为 A2H2+A1(H1+H2) ——式二 ; 由 式一 小于 式二 得 , A2H1<A1H2 ,两边同除 H1H2 ,A2/H2<A1/H1 。

所以用所有英雄的 攻击值除以血量 , 将所得的值 从大到小 排序,然后依次攻击即可。


#include<cstdio>
#include<algorithm>

struct HR
{
	int dfs,hp;
	double quo;
	friend operator<(HR& x,HR& y){
	return (x.quo==y.quo)?x.hp<y.hp:x.quo<y.quo;
	}
}H[22];

int N,td,ans;

int main()
{
	//freopen("in.txt","r",stdin);

	while(scanf("%d",&N)!=EOF){

		for(int i=0;i<N;i++){
			scanf("%d%d",&H[i].dfs,&H[i].hp);
			td+=H[i].dfs;
			H[i].quo=1.0*H[i].hp/H[i].dfs;
		}

		std::sort(H,H+N);

		int i=0;ans=0;
		while(i<N){
			ans+=H[i].hp*td;
			td-=H[i].dfs;
			i++;
		}

		printf("%d\n",ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值