当前位置:网站首页>[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 2∣n . but n = 1 n=1 n=1 and n = 3 n=3 n=3 There is no solution . guess 2 ∤ n 2\nmid n 2∤n 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(1⩽i⩽2n) by , Walk the [ i − 1 , i ] [i{-}1,i] [i−1,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 2∤n 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 m⩽8 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;
}
The writer Rainybunny \textsf{Rainybunny} Rainybunny, meaning XY \text{XY} XY, Crooked fork . ︎
边栏推荐
- Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
- The Rust Programming Language
- Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
- Controlling volume mixer
- JS to determine whether an element exists in the array (four methods)
- What does cardinality mean in set
- How to deploy locally developed SAP ui5 applications to ABAP servers
- Wechat applet simply realizes chat room function
- SAP QM executes the transaction code qp01, and the system reports an error -material type food is not defined for task list type Q-
- [short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]
猜你喜欢

joda.time获取日期总结

Navicat防止新建查询误删

Cs8126t 3.1w mono ultra low EMI unfiltered class D audio power amplifier IC

Can TCP syn handshake messages transmit data

Understand what ICMP Protocol is

Face++ realizes face detection by flow

Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance

Arm register (cortex-a), coprocessor and pipeline

How two hosts in different network segments directly connected communicate

ACWING/2004. 错字
随机推荐
How to deploy locally developed SAP ui5 applications to ABAP servers
Analysis on the scale of China's smart airport industry in 2020: there is still a large space for competition in the market [figure]
Uncaught typeerror cannot set properties of undefined (setting 'classname') reported by binding onclick event in jsfor loop
TCP BBR as rate based
Introduction to sap ui5 tools
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]
How two hosts in different network segments directly connected communicate
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
The Rust Programming Language
MSG_ OOB MSG_ PEEK
Analysis of China's food cold chain logistics, output of quick-frozen noodles and rice products and operation of major enterprises in 2021 [figure]
Streaming a large file using PHP
General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
了解zbrush雕刻软件,以及游戏建模的分析
JD 7 head search navigation layout
joda.time获取日期总结
Is it safe to open a stock account on the Internet in Beijing?
How to create a handy vs Code?
ASP. Net core - encrypted configuration in asp NET Core