ACM 之 K - Hero

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

理解

你血无线但是攻击力只有1,面对敌方英雄,用最少的血量损失把他们都打败.寻找那些攻击力非常高然后血又比较少的英雄先进行攻击.

代码部分

#include
#include
using namespace std;
int n,i,j; long long HP_loss,total_d;
struct node
{
    int h,d;
}N[20];
int cmp(node &a,node &b)
{
    return a.d*1.0/a.h>b.d*1.0/b.h;
}
int main()
{
    while(cin>>n)
    {
        HP_loss=0,total_d=0;
        for(i=0;i>N[i].d>>N[i].h;
            total_d+=N[i].d;
        }
        sort(N,N+n,cmp);
        for(i=0;i

意见反馈 || 任何建议

联系我(新浪)
邮箱:[email protected]

你可能感兴趣的:(ACM 之 K - Hero)