当前位置:网站首页>[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 . ︎
边栏推荐
- 'how do I create an enumeration with constant values in rust?'- How can I create enums with constant values in Rust?
- Query process of MySQL secondary index
- Derivation of COS (a-b) =cosa*cosb+sina*sinb
- 【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
- Unity获取资源路径
- ACWING/2004. Misspelling
- Analysis of common interview questions in redis
- How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
- VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
- joda.time获取日期总结
猜你喜欢
![[200 opencv routines of youcans] 104 Motion blur degradation model](/img/a9/8841ffc8bd3c486bc4011a1a84ff45.jpg)
[200 opencv routines of youcans] 104 Motion blur degradation model

Ht513 I2S input 2.8W mono class D audio power amplifier IC
![[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)](/img/73/2ec957d58616d692e571a70826787f.jpg)
[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)

DNS domain name system

Power representation in go language

cos(a-b)=cosa*cosb+sina*sinb的推导过程

原子Alpha开发板--SD卡和emmc烧录工具

How to realize hierarchical management of application and hardware in embedded projects

Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)

Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution
随机推荐
Record of friend guide
ASP. Net core - Safety of asynclocal in asp NET Core
In depth inventory: 23 vscode plug-in artifacts that improve development efficiency and aesthetics
CTFHub-Web-信息泄露-目录遍历
joda.time获取日期总结
The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
Derivation of sin (a-b) =sina*cosb-sinb*cosa
Derivation of sin (a+b) =sina*cosb+sinb*cosa
Derivation of COS (a+b) =cosa*cosb-sina*sinb
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
sin(a-b)=sina*cosb-sinb*cosa的推导过程
How to realize hierarchical management of application and hardware in embedded projects
Derivation of COS (a-b) =cosa*cosb+sina*sinb
Baidu map - introductory tutorial
十大券商公司哪个佣金最低,最安全可靠?有知道的吗
Acwing2013. three lines
Uncaught typeerror cannot set properties of undefined (setting 'classname') reported by binding onclick event in jsfor loop
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
ACWING2013. 三条线
[no title] dream notes 2022-02-20