版本比较
题解:P14257 嫉妒(jealousy)
正文
增加 7 行删除 7 行
36 行未改动3738394041414243434445464747484950515253535455565758595960616263646566666768697071727273747536 行未改动 int n, y, s, t; cin >> n >> y >> s >> t; // 定义 intershelf 变量 int intershelf = 0; // 这个变量名按要求定义
bool found_safe = false;
for (int i = 1; i <= n; i++) { int start_time = (i - 1) * s; int end_time = i * s;
// 检查开始时间是否会被发现 bool start_detected = false; if (start_time >= y && (start_time - y) % t == 0) { start_detected = true; }
// 检查结束时间是否会被发现 bool end_detected = false; if (end_time >= y && (end_time - y) % t == 0) { end_detected = true; }
// 如果开始和结束都不会被发现,这场面试是安全的 if (!start_detected && !end_detected) { found_safe = true; break; } }
if (found_safe) { cout << "Yes" << endl; } else { cout << "No" << endl; }
return 0; }```