hdu 4310 Hero 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4310
贪心水
题目大意:以DotA为背景,英雄PK一对多,我方英雄不死,问杀死敌方所有英雄的时候,我方min英雄战损(掉血量)。
题目分析:一句话先打高伤血少的(贪的原则)。
code:
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int dps,hp;
}hero[29];
bool cmp(node a,node b)
{
return a.hp*b.dps > a.dps*b.hp;
}
int main()
{
int n,hurt,p=0;
while(scanf("%d",&n)!=EOF)
{
hurt=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&hero[i].dps,&hero[i].hp);
if(hero[i].hp==0)continue;
}
sort(hero,hero+n,cmp);
for(int i=0;i<n;i++)
for(int j=i;j<n;j++)
hurt+=hero[i].dps*hero[j].hp;
printf("%d\n",hurt);
}
return 0;
}
PS:很久了,终于自己A了……继续补欠吧