Files
python/TangDou/CSP-J/AcWingTraining/T7/431_DP.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

33 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
using namespace std;
const int N = 300010;
int m; // 初始魔法值
int s; // 他所在的初始位置与岛的出口之间的距离
int t; // 岛沉没的时间
int f[N]; // f[i]数组表示第i秒时守望者所能到的最远距离
int main() {
cin >> m >> s >> t;
for (int i = 1; i <= t; i++) { // 相当于第一次提交的程序
if (m >= 10) { // 能闪烁尽量闪烁
m -= 10;
f[i] = f[i - 1] + 60; // 最大距离可以增加60米
} else {
m += 4; // 不能闪烁,那么就站在原地回血
f[i] = f[i - 1]; // 距离没有长大
}
}
// 问题是站在原地回血不一定是最优选择,也可以在此时选择跑步啊~
for (int i = 1; i <= t; i++) {
f[i] = max(f[i], f[i - 1] + 17); // 如果在第i秒时跑步能到达更远距离,我们跑步
if (f[i] >= s) { // 已到达就可以输出+结束程序啦
cout << "Yes" << endl;
cout << i << endl;
return 0;
}
}
cout << "No" << endl;
cout << f[t] << endl; // 如果进行到了这里说明无法逃离,我们输出能到达的最远距离
return 0;
}