P1095 [NOIP2007 Popularization Group] The Escape of the Watcher

Generally speaking, if you can dodge, you can dodge. If you can dodge, you must be faster than running. Do it in batches and judge which one is faster.

Just go to the code, there are comments in it,

#include <iostream>

using namespace std;

const int N = 3e5 + 5;
int M, S, T, blue[N], dp[N];
//dp[i] 第i秒跑(闪)出的最远距离
//blue[i] 第i秒全靠用蓝闪出的距离

int main() {
	cin >> M >> S >> T;
	for (int i = 1; i <= T; i ++) {
		//跑
		dp[i] = dp[i - 1] + 17;

		//能闪则闪
		if (M >= 10)
			blue[i] = blue[i - 1] + 60, M -= 10;

		//不闪休息
		else
			blue[i] = blue[i - 1], M += 4;

		if (dp[i] < blue[i]) //闪的更快
			dp[i] = blue[i];

		if (dp[i] >= S) { //到啦
			cout << "Yes" << '\n' << i;
			return 0;
		}
	}
	//完了,到不了
	cout << "No" << '\n' << dp[T];
	return 0;
}

Question link: https://www.luogu.com.cn/problem/P1095

Guess you like

Origin blog.csdn.net/weixin_71529971/article/details/131690426