跳到正文

题解

AT_abc347_c 题解

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

文章信息

发布
2024年3月30日
收录
2025年12月12日
更新
2026年10月27日
篇幅
约 1 分钟
获赞
1

版本

  1. v1当前

思路

首先将每个 did_i 变成 di mod (a+b)d_i\bmod(a+b),然后排序,破环成链,di+n=di+a+bd_{i+n}=d_i+a+b,枚举每个 i=1∼ni=1\sim n,判断 di∼di+n−1d_i\sim d_{i+n-1} 相隔距离是否在 aa 天内。

代码

C++
# include <bits/stdc++.h>
using namespace std;
int n, a, b, x[400005], s;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n >> a >> b;
	s = a + b;
	for (int i = 0; i < n; ++ i)
		cin >> x[i], x[i] %= s;
	sort (x, x + n);
	for (int i = 0; i < n; ++ i)
		if (x[i + n - 1] - x[i] < a) {
			cout << "Yes";
			return 0;
		} else
			x[i + n] = x[i] + s;
	cout << "No";
	return 0;
}
原文