当前位置:网站首页>[acnoi2022] the structure of President Wang

[acnoi2022] the structure of President Wang

2022-06-25 06:40:00 OneInDark

subject

Background
drop —— drop —— Kick 1 fork ! You really can't Black topic structure , I can't help you Kill a headmaster Wang !

Title Description
It can be seen in The headmaster's blog .

Ideas

Nothing , First consider taking m = 2 n + 1 m=2n+1 m=2n+1 Partial division . Small hand play situations , Find out n = 2 n=2 n=2 Have solution , And all the 2 ∣ n 2\mid n 2n . but n = 1 n=1 n=1 and n = 3 n=3 n=3 There is no solution . guess 2 ∤ n 2\nmid n 2n unsolvable . At the time of the game, I couldn't understand why , So I sent it

In fact, we have noticed that : remember p i    ( 1 ⩽ i ⩽ 2 n ) p_i\;(1\leqslant i\leqslant 2n) pi(1i2n) by , Walk the [ i − 1 , i ] [i{-}1,i] [i1,i] After this period , Which section should we go next . first p i = i + 1 p_i=i+1 pi=i+1, Specially , Make p 2 n = 1 p_{2n}=1 p2n=1 . that a , b a,b a,b Build wormholes between , Equivalent to exchange p a , p b p_a,p_b pa,pb . Last p i p_i pi Constitute a substitution , And 1 1 1 Points in the same permutation ring will be passed .

that m = 2 n + 1 m=2n+1 m=2n+1 Hope to find a complete even length permutation ring , However 2 ∤ n 2\nmid n 2n It shows that it is an odd arrangement , So I sent it .

It is crucial to think of replacement . Then again , When you realize “ There can be no dead cycle ” When , You should think about it from the perspective of replacement

Then consider m ⩽ 8 m\leqslant 8 m8 This part is divided into . Find a point where neither side is passed , It can be matched arbitrarily , And such points can only be matched internally .

thus , We are passed by the situation according to the needs of the left and right sides , There are four types of points N ( o n e ) , A ( l l ) , L ( e f t ) , R ( i g h t ) N(one),A(ll),L(eft),R(ight) N(one),A(ll),L(eft),R(ight) . So obviously , N N N and N N N pairing , L L L and R R R pairing , A A A and A A A pairing . that N N N Class points do not need to be considered . This is a Simplification problem The way .

So... Is left A L R A L R A ALRALRA ALRALRA Things like that . If A A A The number is 4 4 4 Multiple , Direct use m = 2 n + 1 m=2n+1 m=2n+1 Scheme construction is enough , Because at this time L R LR LR It is equivalent to an episode on the road . If A A A The number of is not 4 4 4 Multiple , We know , The key contradiction lies in the reverse order to parity . Then maybe a couple L R A A L R {\color{red}L}{\color{blue}R}AA{\color{blue}L}{\color{red}R} LRAALR, Then blue with blue 、 Red with red .

Visible by drawing , Its effect is a replacement ring inside 、 An outer permutation ring . Hand play knows , As long as both rings exist A A A, The two can be spliced together . In contrast , If there is no such pattern \text{pattern} pattern No solution . Because this is the only way to save this evil in reverse order .

Of course, the above only shows that there is a solution , In fact, the way to construct the solution is very s i m p l e \rm simple simple: Just find A L R A L R ALRALR ALRALR, except L R LR LR As I said before pattern \text{pattern} pattern even , And then A A AA AA Just connect it . Of course, it's outside A A A It can also be on the right .

Code

#include <cstdio>
#include <algorithm> // Almighty XJX yyds!!
#include <cstring> // oracle: ZXY yydBUS!!!
#include <cctype> // Huge Egg Dog ate me!!!
#include <cstdlib>
using llong = long long;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
# define rep0(i,a,b) for(int i=(a); i!=(b); ++i)
inline int readint(){
    
	int a = 0, c = getchar(), f = 1;
	for(; !isdigit(c); c=getchar()) if(c == '-') f = -f;
	for(; isdigit(c); c=getchar()) a = a*10+(c^48);
	return a*f;
}

const int MAXN = 200005;
bool vis[MAXN];	int match[MAXN];

int nxt[MAXN];
int main(){
    
	int n = readint(), m = readint(), cnta = 0;
	while(m--) vis[readint()] = true;
	{
     // basic matching for 'N'
		int lstn = -1;
		for(int i=1; i<=(n<<1); ++i)
			if(!vis[i-1] && !vis[i]){
     // 'N'
				if(!(~lstn)){
     lstn = i; continue; }
				match[i] = lstn, match[lstn] = i, lstn = -1;
			}
			else if(vis[i-1] && vis[i]) ++ cnta;
		if(~lstn){
     puts("No"); return 0; }
	}
	if((cnta&3) == 2){
    
		bool flag = false;
		rep(i,1,n<<1) if(vis[i-1] && vis[i]){
     // 'A'
			int rig = i; while(rig <= (n<<1) &&
				vis[rig-1] && vis[rig]) ++ rig;
			int zuo[3] = {
    0,0,0};
			for(int j=i-1; j; --j)
				if(!vis[j-1] && vis[j]) zuo[2] = j;
				else if(vis[j-1] && !vis[j]){
    
					zuo[1] = j; break; // collected
				}
			if(!zuo[1]){
     i = rig-1; continue; }
			for(int j=zuo[1]-1; j; --j)
				if(vis[j-1] && vis[j]){
    
					zuo[0] = j; break;
				}
			int you[3] = {
    i,i,i};
			for(int j=i+1; j<=(n<<1); ++j)
				if(vis[j-1] && !vis[j]) you[0] = j;
				else if(!vis[j-1] && vis[j]){
    
					you[1] = j; break;
				}
			if(you[1] != i)
				for(int j=you[1]+1; j<=(n<<1); ++j)
					if(vis[j-1] && vis[j]){
    
						you[2] = j; break;
					}
			if(zuo[0] && you[1] != i){
     // link to left
				match[zuo[0]] = i, match[i] = zuo[0];
				match[zuo[1]] = you[1], match[you[1]] = zuo[1];
				match[zuo[2]] = you[0], match[you[0]] = zuo[2];
				flag = true; break;
			}
			if(zuo[1] && you[2] != i){
     // link to right
				match[rig-1] = you[2], match[you[2]] = rig-1; 
				match[zuo[1]] = you[1], match[you[1]] = zuo[1];
				match[zuo[2]] = you[0], match[you[0]] = zuo[2];
				flag = true; break;
			}
			i = rig-1; // skip the segment
		}
		if(!flag){
     puts("No"); return 0; }
	}
	int lstl = -1, lsta[4] = {
    -1,-1,-1,-1};
	puts("Yes"); // can be sure
	for(int i=1|(cnta=0); i<=(n<<1); ++i){
    
		if(match[i]){
    
			if(match[i] < i)
				printf("%d %d\n",match[i],i);
			continue; // 'N' or known
		}
		if(vis[i-1] && vis[i]){
     // 'A'
			lsta[cnta++] = i;
			if(cnta == 4){
     // done
				printf("%d %d\n%d %d\n",lsta[0],
				  lsta[2],lsta[1],lsta[3]);
				cnta = 0; // reset
			}
		}
		else if(vis[i-1]) // 'L'
			lstl = i; // assert(lstl == -1);
		else printf("%d %d\n",lstl,i);
	}
	return 0;
}

  1. The writer Rainybunny \textsf{Rainybunny} Rainybunny, meaning XY \text{XY} XY, Crooked fork .

原网站

版权声明
本文为[OneInDark]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250436029512.html