Hero
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 9759 Accepted Submission(s): 3919
Problem 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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
const int maxn = 20 + 5;
struct Node {
int hp, dps;
double per;
Node(int dps = 0, int hp = 0) : dps(dps), hp(hp) {
if (hp) per = 1.0 * dps / hp;
}
bool operator < (const Node& rhs) const {
return per > rhs.per;
}
};
int n, sum, ans;
vector<Node> enemy;
inline void init() {
enemy.clear();
sum = ans = 0;
}
int main() {
while (~scanf("%d", &n)) {
init();
int u, v;
for (int i = 0; i < n; i++) {
scanf("%d%d", &u, &v);
enemy.push_back(Node(u, v));
sum += u;
}
sort(enemy.begin(), enemy.end());
for (auto i : enemy) {
ans += sum * i.hp;
sum -= i.dps;
}
printf("%d\n", ans);
}
return 0;
}
本文探讨了在游戏《DotA》中面对1vN不利局势时的最佳策略,通过算法计算最小生命值损失。考虑英雄的两个关键属性:健康点(HP)和每射击一次造成的伤害(DPS),算法采用贪心策略,优先攻击每单位HP造成的伤害最大的敌人。
488

被折叠的 条评论
为什么被折叠?



