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.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 25
#define eps 1e-8
using namespace std;
//用一个结构体来储存敌人的2个属性
typedef struct cw{
int dps;
int hp;
} sc;
sc enemy[N];
int cmp(sc x,sc y)
{
return 1.0*x.dps/x.hp-1.0*y.dps/y.hp<eps;//比较浮点数大小会有误差
}
int main()
{
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d %d",&enemy[i].dps,&enemy[i].hp);
}
if(n==)printf("%d\n",enemy[].dps*enemy[].hp);
else {
sort(enemy,enemy+n,cmp);//以单位血量DPS大小排序
int sum=;
for(int i=n-;i>=;i--){
//这是你杀一个enemy时受到的伤害
sum+=enemy[i].dps*enemy[i].hp;
for(int j=;j<i;j++){
//这是其他enemy同时对你造成的伤害
sum+=enemy[j].dps*enemy[i].hp;
}
}
printf("%d\n",sum);
}
}
return ;
}