题解 AT5140 【[AGC035C] Skolem XOR Tree】
[AGC035C] Skolem XOR Tree
月考之余做做构造题玩玩。
这个题比较好地考察了一些异或的性质。在一般的情况下我们用的较多的是异或的交换律,以及自己异或自己为
首先,我们要知道一点,对于一个偶数 1xxxxx0 的,加上 1xxxxx1 了,根据异或的计算方式,前面都是相同位,故为
接着还有一点,不妨设
那么我们知道了这么多奇怪的性质,能做什么呢?
首先考虑一下这个题的无解情况。当
那么别的情况下呢?其实根据第一条性质,会发现别的情况一定有解。
既然对于偶数
然后会发现这么做,要对
因为
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int main()
{
int n=read();
if (!(n&(n-1)))
puts("No");
else
{
puts("Yes");
puts("1 2");
puts("2 3");
cout << 3 << " " << n+1 << endl;
cout << n+1 << " " << n+2 << endl;
cout << n+2 << " " << n+3 << endl;
for (int i=4;i+1<=n;i+=2)
{
int j=i+1;
cout << 1 << " " << i << endl;
cout << 1 << " " << j << endl;
cout << i << " " << j+n << endl;
cout << j << " " << i+n << endl;
}
if (n%2==0)
{
for (int i=4;i<=n;i++)
{
int j=n^i^1;
if (j!=3 && j<n)
{
cout << i << " " << n << endl;
cout << j << " " << 2*n << endl;
return 0;
}
}
}
}
return 0;
}