[构造] Codeforces 804E Round #411 (Div. 1) E. The same permutation

打表发现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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值