然后模拟k次,每次从0开始,一直到1024(因为最大是1000,异或之后可能出现的最大值是1024),根据每个数前面已经出现了几个可以判断这个数第一次出现在按从小到大的排序的序列里是否为第奇数个
例如 1 1 2 2 2 3 3 3
有两个1,并且前面没有任何数,所以这两个1里有一个要异或x,一个不变,三个2,,2前面有两个数,所以第一个2是位于奇数的位置,这三个2里有两个要异或x,一个不变,
三个3,而第一个3是位于偶数的位置,所以三个3里只有一个要异或x
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MEM(a) memset(a,0,sizeof(a));
#define res(i,be,n) for(i=be;i<n;i++)
int main()
{
int n,x,k,a[1030],b[1030],t,i,j,re;
scanf("%d %d %d",&n,&k,&x);
MEM(a);
MEM(b);
res(i,0,n)
{
scanf("%d",&j);
a[j]++;
}
res(i,0,k)
{
t=0;
res(j,0,1025)
{
b[j]=a[j];
}
MEM(a);
res(j,0,1025)
{
re=(b[j]+!(t&1))/2;
a[j^x]+=re;
a[j]+=b[j]-re;
t+=b[j];
}
}
int maxx=0,minn=1024;
res(i,0,1025)
if(a[i])
{
maxx=max(maxx,i);
minn=min(minn,i);
}
printf("%d %d\n",maxx,minn);
return 0;
}