普通的贪心题。排序后遍历看杀死每个怪需要多少血,加起来即可。刚开始得数对的,但是A不掉。搜了下题解,结果居然有人说是double,题上不明写着 each contains two integers DPSi and HPi吗,我真是日了狗了。。。最后发现是排序函数有问题,看来还是图样奶义务啊。。。
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 5005;
const int INF = 1<<27;
struct HERO
{
int hp;
int dps;
}hero[N];
/*bool cmp(HERO a, HERO b)
{
if(a.dps != b.dps)
return a.dps > b.dps;
else
return a.hp < b.hp;
}*/
bool cmp(const HERO &a,const HERO &b)
{
return a.hp*b.dps<a.dps*b.hp;
}
int main()
{
// freopen("in.txt", "r", stdin);
int n, i, ans, sum;
while(~scanf("%d", &n) )
{
sum = 0;
for(int i = 1; i <= n; i ++)
{
scanf("%d%d", &hero[i].dps, &hero[i].hp);
sum += hero[i].dps;
}
sort(hero + 1, hero + n + 1, cmp);
ans = 0;
for(i = 1; i <= n; i ++)
{
ans += sum * hero[i].hp;
sum -= hero[i].dps;
}
printf("%d\n", ans);
}
return 0;
}