203 字
1 分钟
题解:P14257 嫉妒(jealousy)

P14257 嫉妒(jealousy)题解#

题目传送门

思路#

对于某一场面试 ii,如果想不被发现,必须同时满足:

  1. 开始时间不被发现:(i−1)×s≠y+j1×t(i-1) \times s \ne y + j_1 \times t 对所有 j1≥0j_1 \ge 0。
  2. 结束时间不被发现:i×s≠y+j2×ti \times s \ne y + j_2 \times t 对所有 j2≥0j_2 \ge 0。

由于小 Y 每隔 tt 分钟出现一次,从 yy 开始,所以小 S 会被小 Y 在第 xx 分钟发现而且仅当 x≥yx \ge y 且 (x−y) mod t=0(x-y) \bmod t=0。

然后枚举每一场面试 ii,只要有一场面试是合法的,那么就输出 Yes,否则输出 No。

时间复杂度为 O(n)O(n)。

Code#

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,y,s,t;
bool check(int x) {
if (x<y) return false;
return (x-y)%t==0;
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>y>>s>>t;
for (int i=1;i<=n;i++)
if (!check((i-1)*s) && !check(i*s)) {
cout<<"Yes";
return 0;
}
cout<<"No";
return 0;
}
题解:P14257 嫉妒(jealousy)
https://banglee13.github.io/posts/p14257/
作者
banglee
发布于
2025-10-21
许可协议
CC BY-NC-SA 4.0

分享文章

生成精美分享图或复制链接,与更多人分享本文。

继续阅读

沿着主题读

基于共同的标签与分类

换条路线

从其他文章中稳定抽取

最后更新于 ,距今已过 400 天

部分内容可能已过时