跳到正文

题解

CF37B 题解

Vitamin_B约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年5月20日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 2 分钟
题目
CF37B

版本

  1. v1当前

思路

首先先按 powpow 从大到小排序,肯定是 powpow 越大越有机会先使用嘛。

因为数据小,所以接下来只要暴力枚举每个回合即可。如果当前回合中,已经无法再加入卷轴且伤害还不及对方的回血速度,那么你再怎么打它都还是满血,无解了。

否则,就在当前能选的卷轴里面贪心取一个伤害最大的卷轴,这一点可以用优先队列实现,直到它死了就不再继续,输出答案。

代码

C++
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
struct node {
	int x, y, id;
	bool operator < (const node& t) const {
		return y < t.y;
	}
} a[1005];
bool cmp (const node& x, const node& y) {
	return x.x > y.x;
}
int n, m, r, sum, j;
vector <pii> ans;
priority_queue <node> q;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n >> m >> r;
	for (int i = 0; i < n; ++ i)
		cin >> a[i].x >> a[i].y, a[i].id = i + 1, a[i].x = m * a[i].x / 100;
	sort (a, a + n, cmp);
	sum = -r;
	for (int i = 0; ; ++ i) {
		m -= max (0, sum);
		if (m <= 0) {
			cout << "YES\n" << i << ' ' << ans.size () << '\n';
			for (pii& k : ans)
				cout << k.first << ' ' << k.second << '\n';
			return 0;
		}
		while (j < n && m <= a[j].x)
			q.push (a[j]), ++ j;
		if (! q.empty ())
			sum += q.top ().y, ans.push_back ({i, q.top ().id}), q.pop ();
		else if (sum <= 0) {
			cout << "NO";
			return 0;
		}
	}
	return 0;
}
原文