当前位置:网站首页>[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 . ︎
边栏推荐
- Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
- 3dmax软件的制作木桶过程:三步流程
- [short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]
- Analysis of China's food cold chain logistics, output of quick-frozen noodles and rice products and operation of major enterprises in 2021 [figure]
- Introduction to sap ui5 tools
- BigDecimal. Summary of setscale usage
- 有能力的人从不抱怨大环境!
- Navicat防止新建查询误删
- ARM processor operating mode
- Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
猜你喜欢
![[core content and derivation] the mystery of human memory system may be just like this](/img/7c/98f27bb55a1a3b74c0ed8fd7fd2cc5.jpg)
[core content and derivation] the mystery of human memory system may be just like this

The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
![[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]](/img/4a/304f262c1c08800aa95f9e2d537e4d.jpg)
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]

Baidu map - introductory tutorial

Laravel8+ wechat applet generates QR code

System dilemma and software complexity: Why are our systems so complex?

Sophomores majoring in mechanics build a manipulator by hand -- full of compromise

keil debug查看变量提示not in scope

Understand what MSS is

Brief introduction and use of JSON
随机推荐
Hongmeng learning notes: creating layouts using XML
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
'how do I create an enumeration with constant values in rust?'- How can I create enums with constant values in Rust?
@Detailed explanation of valid annotation usage
Zhinai's database
sin(a-b)=sina*cosb-sinb*cosa的推导过程
Usage of STL map
Power representation in go language
Understand what MTU is
Ht513 I2S input 2.8W mono class D audio power amplifier IC
Are these old system codes written by pigs?
Which of the top ten securities companies has the lowest Commission and is the most safe and reliable? Do you know anything
At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
燕京啤酒何以至此?
After unplugging the network cable, does the original TCP connection still exist?
System dilemma and software complexity: Why are our systems so complex?
keil debug查看变量提示not in scope
What is the IP address
Streaming a large file using PHP
cos(a-b)=cosa*cosb+sina*sinb的推导过程