HDU 4310 贪心

题意 在游戏中你的dps为1但是hp无限 给出n个敌人的dps与hp 你一秒能打掉一个敌人你的dps的hp 当你输出的时候 所有活着的敌人都会打你 求杀死所有敌人时你掉的最少hp

一开始想错了 排序的时候先处理了dps更高的 然后wa

即使在游戏中这也是很傻的..

应该处理dps/hp更高的 如果放在游戏里讲应该是先杀输出能力高的...

如果直接return a.dps/a.hp>b.dps/b.hp会出现小数

所以用 return a.dps*b.hp>b.dps*a.hp

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
struct node
{
    long long int dps;
    long long int hp;
};
node a[25];
int cmp(node a,node b)
{
    return a.dps*b.hp>b.dps*a.hp;
}
int main(){
int n;
while(~scanf("%d",&n))
{
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d%I64d",&a[i].dps,&a[i].hp);
        sum+=a[i].dps;
    }
    sort(a+1,a+1+n,cmp);
    long long int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=sum*a[i].hp;
        sum-=a[i].dps;
    }
    printf("%I64d\n",ans);
}
}

  

posted @ 2016-02-25 01:21  天翎月  阅读(248)  评论(0编辑  收藏  举报