标签:min temp etc else geo for using turn pa2014
显然是贪心题吧,dp感觉并不能做
如果某一个怪可以回血,那么一定先打伤害低的
对于不能回血的怪,先打恢复血量高的
我们考虑已经知道了最后的血量,然后反过来考虑,一定是尽量加比较小的,才能使最后的血量尽量大
那么就变成每一次尽量取剩下的怪中回血量最大的那个
模拟一遍即可
时间复杂度:\(O(n\ log\ n)\)
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
template <typename node> void chkmax(node &x, node y) {x = max(x, y);}
template <typename node> void chkmin(node &x, node y) {x = min(x, y);}
template <typename node> void read(node &x) {
x = 0; int f = 1; char c = getchar();
while (!isdigit(c)) {if (c == ‘-‘) f = -1; c = getchar();}
while (isdigit(c)) x = x * 10 + c - ‘0‘, c = getchar(); x *= f;
}
struct Node {
int x, y, num, id;
bool operator < (const Node &a) const {
return num < a.num;
}
} a[N], b[N];
int ans[N];
main() {
int n, m, l1 = 0, l2 = 0;
read(n), read(m);
for (int i = 1; i <= n; i++) {
int x, y; read(x), read(y);
if (x <= y) a[++l1] = (Node) {x, y, x, i};
else b[++l2] = (Node) {x, y, -y, i};
}
sort(a + 1, a + l1 + 1), sort(b + 1, b + l2 + 1);
int len = 0;
for (int i = 1; i <= l1; i++)
if (m <= a[i].x) {cout << "NIE\n"; return 0;}
else m += a[i].y - a[i].x, ans[++len] = a[i].id;
for (int i = 1; i <= l2; i++)
if (m <= b[i].x) {cout << "NIE\n"; return 0;}
else m += b[i].y - b[i].x, ans[++len] = b[i].id;
cout << "TAK\n";
for (int i = 1; i <= n; i++) cout << ans[i] << ‘ ‘;
cout << "\n";
return 0;
}
标签:min temp etc else geo for using turn pa2014
原文地址:https://www.cnblogs.com/copperoxide/p/9483476.html