CF-1362B. Johnny and His Hobbies
Posted valk3
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF-1362B. Johnny and His Hobbies相关的知识,希望对你有一定的参考价值。
B. Johnny and His Hobbies
题意
给出n个数字,让找出最小的正整数k,使得这n个数字异或k之后,还是这n个数字。
思路
n以及n个数字都不大,直接暴力枚举k为1~1024。
代码
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1024+10;
const int mod=50331653;
const int inf=0x3f3f3f3f;
typedef unsigned long long ull;
typedef long long ll;
int arr[N],rec[N][N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; ++i)
{
scanf("%d",&arr[i]);
for(int j=1; j<1024; ++j)
rec[j][i]=arr[i]^j;
}
sort(arr+1,arr+1+n);
int ans=-1;
for(int i=1; i<1024; ++i)
{
sort(rec[i]+1,rec[i]+1+n);
int flag=1;
for(int j=1;j<=n;j++)
{
if(rec[i][j]!=arr[j])
{
flag=0;
break;
}
}
if(flag)
{
ans=i;
break;
}
}
printf("%d
",ans);
}
return 0;
}
/*
*/
以上是关于CF-1362B. Johnny and His Hobbies的主要内容,如果未能解决你的问题,请参考以下文章
CF-1362D. Johnny and Contribution
CF-1362D. Johnny and Contribution
CF-1362C. Johnny and Another Rating Drop
CF-1362C. Johnny and Another Rating Drop
Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)
Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)