题意
V11是一个无敌的人(打不死),但是他的攻击力有限,每回合怪物和v11同时互相攻击,问最少V11受到的伤害、
思路
有点要绕hhh
开始的时候可能会认为是攻击力越高越先处理。但是仔细考虑之后贪心点不仅仅由攻击力决定,还要它的生命值同时决定。勇士在攻击一个怪兽的同时别的怪兽也在攻击勇士,他们的伤害也在叠加。所以优先消灭的怪兽有两个因素同时的决定即有怪兽的攻击力和生命值的比值决定,攻击和生命值比值高的怪兽需要先处理掉。
觉得另一个的数学公式更直观准确,不过更难想的感觉hhh
通过比较两个怪物到底先杀任意一个会受到的伤害,列出公式,来确定到底对哪个值贪心
代码
// https://blog.csdn.net/u011806194/article/details/51897908
// https://blog.csdn.net/qq_32866009/article/details/50698255
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 10000 + 10;
struct Monster {
int times, atk;
bool operator< ( const Monster &rhs ) const { return times * rhs.atk < rhs.times * atk; }
} mon[ maxn ];
int n, m;
int main () {
int T;
scanf ( "%d", &T );
for ( int ks = 1; ks <= T; ++ks ) {
scanf ( "%d%d", &n, &m );
for ( int i = 0; i < n; ++i ) {
int hp, atk;
scanf ( "%d%d", &hp, &atk );
mon[ i ].times = ( hp + m - 1 ) / m;
mon[ i ].atk = atk;
}
sort ( mon, mon + n );
int sum = 0;
ll ans = 0;
for ( int i = 0; i < n; ++i ) {
sum += mon[ i ].times;
ans += sum * mon[ i ].atk;
}
printf ( "Case #%d: %lld\n", ks, ans );
}
return 0;
}