Description
最近流行一款网游英雄联盟,类似dota的5V5对战游戏,其中一个远程攻击英雄深渊巨口·克格莫,非常强力,团战的时候站着喷,就可能拯救世界……
我们现在计算一个简单的数据,假设克格莫倒霉的遇到了对面五个人偷袭,克格莫在挂掉之前可以对敌人进行若干次攻击,友军即将包抄过来,所以克格莫只想造成尽可能高的伤害,并不追求杀掉哪一个。那么,它最高能制造多高的输出?
Input
每组数据第一行为正整数n(0 < n < 20),表示克格莫挂掉之前可以进行的攻击次数,接下来5行,代表对敌方五个人能造成的伤害。每行两个数,第一个数是敌人的生命值,第二个数是一次攻击能产生的伤害。如果一次伤害之后敌人的生命值小于0,本次伤害值依然按能够制造的伤害值计算,而下次不能再攻击这个挂掉的敌人。敌人生命值不超过5500,攻击能产生的伤害不超过550。
Output
每组数据输出一行,克格莫可以打出的最高伤害。
Sample Input
10 1000 300 5000 200 4000 500 3000 100 2000 550
Sample Output
5200
思路:典型的贪心。
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int sm, sh;
};
bool cmp(node a, node b)
{
return a.sh > b.sh;
}
int main()
{
int n;
node nod[5];
while (cin>>n)
{
for (int i = 0; i < 5; i++)cin >> nod[i].sm >> nod[i].sh;
sort(nod, nod + 5, cmp);
int ans = 0, t;
for (int i = 0; n; i++)
{
t = (nod[i].sm - 1) / nod[i].sh + 1;
if (t > n)t = n;
n -= t, ans += t * nod[i].sh;
}
cout << ans << endl;
}
return 0;
}