Hero

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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
 
 
//又是贪心算法,题目就是要你一个人打N个人,然后输出最后你受到的伤害,最划算的方法不是先打攻击力高的,也不是血量少的,而是攻击力与血量比值最高的。嘛,也就是传说中中的性价比啦~
那就按性价比从高到低排序吧~
注意的地方是你在攻击他人的时,其余人也会对你造成伤害哦!也就是说在你打败一个人之前,你受到的伤害都是所有人的总攻击力啦,直到你把一个人打败才能改变,也就是说从开始,到打败一个人所受伤害即是被击败者的血量乘以初始所有人的总攻击力,然后减去被打败者的攻击力,继续循环下去....
代码如下:
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;

struct Enemy
{
    int hp;
    int dps;
}enemy[25];

bool cmp(const Enemy &a,const Enemy &b)
{
    return (double)a.dps/(double)a.hp>(double)b.dps/(double)b.hp;
}

int main()
{   int n;
    while(~scanf("%d",&n))
    {   int myhp=0;
        int alldps=0;
        memset(enemy,0,sizeof(enemy));
        for (int i=0;i<n;i++)
        {
            scanf("%d %d",&enemy[i].dps,&enemy[i].hp);
            alldps+=enemy[i].dps;
        }
            sort(enemy,enemy+n,cmp);
        for(int i=0;i<n;i++)
        {
            myhp+=enemy[i].hp*alldps;
            alldps-=enemy[i].dps;
        }
        printf("%d\n",myhp);
    }
    return 0;
}
View Code

 

posted @ 2016-07-20 19:11  君子酱  阅读(215)  评论(0编辑  收藏  举报