跳到正文

题解

P13713 晴天 题解

Obsith约 5 分钟
原文
文章信息与版本

文章信息

发布
2025年8月13日
收录
2025年12月12日
更新
2026年10月10日
篇幅
约 5 分钟
获赞
1
题目
P13713

版本

  1. v1当前

前言

如果你在过 A 以后看榜发现有一众人 B 有 10 pts,那么可以试试传说中的 45%45\% 正确率大法,这样你会获得 rk20- 五分钟体验卡一张~

10pts

输出 -2 。致敬传奇总司令!

Sub3 显然都不合法。

注意到至少有两雨天,所以 x+y+2>nx+y+2>n 时无解。

25pts

Sub5:只构造一种天气,以晴天举例,试图构造:

  • x=1:1,0,0,0,0,0,0,…x=1:1,0,0,0,0,0,0,\dots
  • x=2:1,1,0,0,0,0,0,…x=2:1,1,0,0,0,0,0,\dots
  • x=3:0,0,1,0,0,0,0,…x=3:0,0,1,0,0,0,0,\dots
  • x=4:1,1,0,1,0,0,0,…x=4:1,1,0,1,0,0,0,\dots
  • x=5:1,1,0,1,1,0,0,…x=5:1,1,0,1,1,0,0,\dots
  • x=6:0,0,1,0,0,1,0,…x=6:0,0,1,0,0,1,0,\dots
  • …\dots

发现规律了吗?模 33 余 1,21,2 时以 (1,1,0)(1,1,0) 为周期,余 00 时以 (0,0,1)(0,0,1) 为周期。

另一种天气同理,用 −1-1 代替即可。

C++
	if(x%3==0) fo(i,1,x) a[i]=(i%3==1?0:1);
	else fo(i,1,x) a[i]=(i%3==0?0:1);

100pts?

考虑怎么合并这两种天气,会发现由于最后一个天气必定要多出一个值导致另一种天气无法像从开头一样构造,似乎陷入僵局。。。

嗯?从开头构造?那么从右端同样可以啊!

于是你写出了如下代码:

C++
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fr(i,l,r) for(int i=l;i>=r;i--)
#define pb push_back
#define fi first
#define se second
#define par pair<int,int>
inline ll rd() {
    ll x = 0, f = 1;
    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();
    }
    return x * f;
}
const int N=1e6+5;
int n,x,y,a[N];
signed main(){
	int T=rd();
	while(T--){
		n=rd(),x=rd(),y=rd();
		fo(i,1,n)a[i]=0;
		if(x+y+2>n) {puts("-2");continue;}
		if(x)
			if(x%3==0) fo(i,1,x) a[i]=(i%3==1?0:1);
			else fo(i,1,x) a[i]=(i%3==0?0:1);
		if(y)
			if(y%3==0) fo(i,1,y) a[n-i+1]=(i%3==1?0:-1);
			else fo(i,1,y) a[n-i+1]=(i%3==0?0:-1);
		fo(i,1,n)printf("%d ",a[i]);puts("");
	}
	return 0;
}

但是 WA 80pts

那么问题出在哪里呢?让我们回头想想,会不会在一开始就早已误入歧途?

正解在下面,不过相信你肯定比我想得更快。

Accepted
C++
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define fr(i,l,r) for(int i=l;i>=r;i--)
#define pb push_back
#define fi first
#define se second
#define par pair<int,int>
inline ll rd() {
    ll x = 0, f = 1;
    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();
    }
    return x * f;
}
const int N=1e6+5;
int n,x,y,a[N];
signed main(){
	int T=rd();
	while(T--){
		n=rd(),x=rd(),y=rd();
		fo(i,1,n)a[i]=0;
		if(x+y+2>n&&(x||y)) {puts("-2");continue;}//x=y=0,n=1
		if(x)
			if(x%3==0) fo(i,1,x) a[i]=(i%3==1?0:1);
			else fo(i,1,x) a[i]=(i%3==0?0:1);
		if(y)
			if(y%3==0) fo(i,1,y) a[n-i+1]=(i%3==1?0:-1);
			else fo(i,1,y) a[n-i+1]=(i%3==0?0:-1);
		fo(i,1,n)printf("%d ",a[i]);puts("");
	}
	return 0;
}

晴天,可不能起雾啊。

原文