跳到正文

题解

题解:P14257 嫉妒(jealousy)

huashao_139约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月14日
更新
2025年12月14日
篇幅
约 1 分钟
题目
P14257

版本

  1. v1当前

形式化题意

是否存在一个正整数 ii 满足 1≤i≤n1 \le i \le n,并且不存在非负整数 jj 使得 (i−1)×s=y+j×t(i−1)\times s=y+j \times t 或者 i×s=y+j×ti\times s=y+j \times t。

很水的题,模拟 ii,jj 即可,复杂度大约 n2st\frac{n^2s}{t}。

具体注意事项见代码。

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,y,s,t;
signed main(){
	cin>>n>>y>>s>>t;
	for(int i=1;i<=n;i++){
		int f1=1,f2=1;
		for(int j=0;y+j*t<=i*s;j++)// 这里一定要写循环终止条件
			if(y+j*t==i*s){// 不然会炸
				f1=0;
				break;
			}
		for(int j=0;y+j*t<=(i-1)*s;j++)// 这里也是
			if(y+j*t==(i-1)*s){
				f2=0;
				break;
			}
		if(f1&&f2){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}
原文