Codeforces 647div2B

Codeforces 647div2B

原题:

Among Johnny’s numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad’s office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.

There is a set SS containing very important numbers on his dad’s desk. The minute Johnny heard about it, he decided that it’s a good idea to choose a positive integer kk and replace each element ss of the set SS with s⊕ks⊕k (⊕⊕ denotes the exclusive or operation).

Help him choose such kk that Johnny’s dad will not see any difference after his son is done playing (i.e. Johnny will get the same set as before playing). It is possible that no such number exists. It is also possible that there are many of them. In such a case, output the smallest one. Note that the order of elements in a set doesn’t matter, i.e. set {1,2,3}{1,2,3} equals to set {2,1,3}{2,1,3}.

Formally, find the smallest positive integer kk such that {s⊕k|s∈S}=S{s⊕k|s∈S}=S or report that there is no such number.

For example, if S={1,3,4}S={1,3,4} and k=2k=2, new set will be equal to {3,1,6}{3,1,6}. If S={0,1,2,3}S={0,1,2,3} and k=1k=1, after playing set will stay the same.

Input
In the first line of input, there is a single integer tt (1≤t≤10241≤t≤1024), the number of test cases. In the next lines, tt test cases follow. Each of them consists of two lines.

In the first line there is a single integer nn (1≤n≤10241≤n≤1024) denoting the number of elements in set SS. Second line consists of nn distinct integers sisi (0≤si<10240≤si<1024), elements of SS.

It is guaranteed that the sum of nn over all test cases will not exceed 10241024.

Output
Print tt lines; ii-th line should contain the answer to the ii-th test case, the minimal positive integer kk satisfying the conditions or −1−1 if no such kk exists.

思路:因为数据范围很小所以暴力枚举就行

ACcodes:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int test=1;
int main()
{
    scanf("%d",&test);
    while(test--)
    {
        int s[1500]={0};
        int n,a[1500];cin>>n;
        bool flag=false;
        int res;
        for(int i=1;i<=n;i++) {int x;cin>>x;a[i]=x;s[x]++;}
        for(int i=1;i<=1024;i++)
        {
            int vis[1025]={0};
            for(int j=1;j<=n;j++)
                vis[i^a[j]]++;
            bool check=true;
            for(int j=0;j<1025;j++)
            {
                if((s[j] && !vis[j]) || (vis[j]&&!s[j]))
                {
                    check = false;
                    break;   
                }
            }
            if(check)
            {
                flag = true;
                res=i;
                break;
            }
        }
        cout << (flag?res:-1) << endl;

    }
    //system("pause");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值