打表发现4是可以做到不变的
然后我们四个划为一块 两块之间16下也是可以不变的
具体
const int xx[]={
1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4
};
const int yy[]={
1,2,3,4,2,1,4,3,3,4,1,2,4,3,2,1
};
这样相当于第一个四下 相当于会把两边对调 然后每个数xor0 第二个四下 每个数xor1 4次下来 1^2^3^0=0
那个xor 是从0开始标号的xor 也就是减1后xor
4k+2 4k+3 无解
4k+1的话 你挑4k的答案其中几次 把4k+1作为中转点就好了 类似把 (a,b) 替换成 (t,a) (a,b) (b,t)
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define pb push_back
using namespace std;
typedef pair<int,int> abcd;
const int x[]={
1,1,2,1,2,3
};
const int y[]={
2,3,4,4,3,4
};
const int xx[]={
1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4
};
const int yy[]={
1,2,3,4,2,1,4,3,3,4,1,2,4,3,2,1
};
int n;
vector<abcd> ans;
int main(){
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
scanf("%d",&n);
if (n%4==2 || n%4==3) return printf("NO\n"),0;
int m=n/4;
for (int i=1;i<=m;i++)
for (int k=0;k<6;k++)
ans.pb(abcd((i-1)*4+x[k],(i-1)*4+y[k]));
for (int i=1;i<=m;i++)
for (int j=1;j<i;j++)
for (int k=0;k<16;k++)
ans.pb(abcd((j-1)*4+xx[k],(i-1)*4+yy[k]));
printf("YES\n");
for (abcd x:ans){
if (x.first>x.second) swap(x.first,x.second);
if ((n==4*m+1 && !(x.first==x.second-1 && (x.first&1))) || n==4*m)
printf("%d %d\n",x.first,x.second);
else{
printf("%d %d\n",x.first,n);
printf("%d %d\n",x.first,x.second);
printf("%d %d\n",x.second,n);
}
}
return 0;
}