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<iostream>
#include<algorithm>
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++)
        {
            cin>>N[i].d>>N[i].h;
            total_d+=N[i].d;
        }
        sort(N,N+n,cmp);
        for(i=0;i<n;i++)
        {
            HP_loss+=total_d*N[i].h;
            total_d-=N[i].d;
        }
        cout<<HP_loss<<endl;
    }
    return 0;
}

意见反馈 || 任何建议

联系我(新浪)
邮箱:qianlizhihao@gmail.com

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,132评论 0 23
  • 我望着那几个要搬上楼的箱子手足无措,我今天要搬家,箱子早就整理好了,我只要把他们直接搬上楼。我的搬家工作就完成了!...
    NPC王小曼阅读 712评论 0 0
  • 真心是这样觉得的。做作业,非要在截止日期才能交上。考试再难的题,在规定时间前还是会填满试卷上所有的空白。再难的难题...
    yhlovelmh阅读 356评论 0 0
  • 气温高的一如往常,三十九度平平。 大早便湿身,汗流夹背,这感觉,太劲爆。 今天在步行来上班还是坐医院车子来上班两者...
    做大王好多年阅读 152评论 0 0