AT_abc347_c 题解

最开始的思路爆炸了我就不写了。

d[i]%=(a+b)

然后,排序,破环为链,相当于存储了下一周。

再然后,从 \(1\)\(n\) 进行一个循环,若 d[i+n-1]-d[i]+1<=a 就输出 Yes

它的原理是什么?

翻译一下上面那个语句,就是“我前一个任务的日期的下一周距离我这个任务的日期小于等于节假日天数”。

那你直接把这个任务放在一周的第一天,其他不就好了!

有人会觉得后面的万一飞到工作日去了的话,会错,但是别忘了我们一周整整 a+b 天,破环为链的时候会加一周的天数,而且我们最初 d[i]%=(a+b) 了,一定是不可能飞到工作日去的。

#include<stdio.h>
#include<bits/stdc++.h>
#define N 1000010
#define MOD 998244353
#define esp 1e-8
#define INF 999999999999999999
#define LL long long
#define rep(i,a,b,g) for(LL i=a;i<=b;i+=g)
#define rem(i,a,b,g) for(LL i=a;i>=b;i-=g)
#define repn(i,a,b,g) for(LL i=a;i<b;i+=g)
#define remn(i,a,b,g) for(LL i=a;i>b;i-=g)
#define pll pair<LL,LL>
#define mkp(x,y) make_pair(x,y)
#define i128 __int128
#define lowbit(x) ((x)&(-(x)))
#define lc (u<<1)
#define rc (u<<1|1)
using namespace std;
void read(i128 &x)
{
	i128 f=1;
	x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}
void writing(i128 x)
{
	if(x>=10)writing(x/10);
	putchar(x%10+'0');
}
void write(i128 x)
{
	if(x<0)
	{
		cout<<'-';
		x=-x;
	}
	writing(x);
}
LL n,a,b,d[400010];
bool f;
int main()
{
	cin>>n>>a>>b;
	rep(i,1,n,1)
	{
		cin>>d[i];
		d[i]%=(a+b);
	}
	sort(d+1,d+n+1);
	rep(i,1,n,1)
	{
		d[i+n]=d[i]+a+b;
	}
	rep(i,1,n,1)
	{
		if(d[i+n-1]-d[i]+1<=a)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}
posted @ 2024-03-30 22:57  cppom  阅读(76)  评论(0编辑  收藏  举报