题目 题解&代码 题意:初始一个空数组 s s s,每次寻找不在数组中的3个不同的数,使得其异或和为0,并加入 s s s中。求 s s s第 n n n个数。 题解:规律发现所有数都会用上,且4进制相关,详见参考题解。
#include "iostream"
#include "stdio.h"
#include "string.h"
#include "algorithm"
using namespace std;
typedef long long ll;
const int N=1e6+5;
const ll mod=998244353;
const double eps=1e-5;
ll f[3][4]={{0,3,1,2},{},{0,2,3,1}};
void solve(ll x,int y)
{
if(y==1)
{
printf("%lld\n",x);
return;
}
ll ans=0,p=1;
while(x)
{
ans=ans+f[y][x%4]*p;
x>>=2;
p_;
while(_--)
{
cin>>n;
ll j=1,a;
while(j=n) a=j;
else a=j+(n-j)/3;
solve(a,n%3);
}
return 0;
}