题解:P17495 [ICPC 2026 Wuhan I] Believe in You
sjh2012zai_lin · · 题解
洛谷P17495
题目大意
你需要累计攻击大于对方血量,且不能有一次防不住,否则就失败了。
做法
优先考虑贪心,每个回合如果可以直接消灭对面就打出所有攻击卡,否则考虑在一定能防住的情况下攻击最高为多少。
思路不难,但比较注重细节。
每次攻击需要注意最多使用3张牌
同理防御也是
:::success[code]
#include <bits/stdc++.h>
#define By return
#define The_Second_Coming 0
#define int long long
using namespace std;
int read() {//快读
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m, ans, s, d, hp;
signed main() {
n = read(), s = read(), d = read(), hp = read();
for (int i = 0; i < n; i++) {
int a = read(), b = 5 - a, sh = read();
if (min(a, 3ll)*s >= hp) {//最多出3张或a张攻击牌
cout << "Yes\n" << i + 1;
return 0;
}
int fy = 0, pk = 0;
for (int j = 0; j < b; j++) {//因为数据不大所以这里我使用的是比较稳的方法,建议初学者使用这种方法
if (fy >= sh)break;
fy += d, pk++;
}
if (pk > 3 || fy < sh) {//不能使用3张以上的防御卡
cout << "No";
return 0;
}
hp -= min(3 - pk, a) * s;//注意 3 - pk 可能大于 a
}
cout << "No";//若 n 个回合内无法解决,则判定为失败
By The_Second_Coming;
}
:::
重现赛时很多细节我也错了