来源:http://codeforces.com/contest/1362/problem/B

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 S 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 k and replace each element s of the set S with s⊕k (⊕ denotes the exclusive or operation).

Help him choose such k 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} equals to set {2,1,3}.

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

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

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

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

It is guaranteed that the sum of n over all test cases will not exceed 1024.

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

Example
inputCopy
6
4
1 0 2 3
6
10 7 14 8 3 12
2
0 2
3
1 2 3
6
1 4 6 10 11 12
2
0 1023
outputCopy
1
4
2
-1
-1
1023
Note
In the first test case, the answer is 1 because it is a minimum positive integer and it satisfies all the conditions.

题意:
给你一个数组n,让你找出最小的数使得异或数组中每一个数之后,数组中的元素不变。

思路:
暴力就ok…

代码:

#include <iostream>
#include <algorithm>
#define maxn 1100
using namespace std;
int a[maxn], b[maxn];
int main()
{int t, n, i, j, flag = 0;cin>>t;while (t--) {cin>>n;for (i = 1; i <= n; i++)cin>>a[i];sort(a + 1, a + 1 + n);for (i = 1; i <= 1024; i++) {flag = 0;for (j = 1; j <= n; j++)b[j] = a[j] ^ i;sort(b + 1, b + 1 + n);for (j = 1; j <= n; j++)if (b[j] != a[j]) { flag = 1;break; }if (!flag)break;}if (!flag)cout << i << endl;else cout<<"-1\n";}return 0;
}

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!B. Johnny and His Hobbies(异或)---题解相关推荐

  1. Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!(AB)

    Johnny and Ancient Computer CodeForces - 1362A 思路:因为除或者乘的都是2的幂次,所以看看二者的商是不是2的幂次就可以了.如果是的话,就3,2,1依次就行 ...

  2. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  3. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  4. Codeforces Round #700 (Div. 2) A ~ E ,6题全,超高质量良心题解【每日亿题】2021/2/8

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Yet Another String Game B - The Great Hero C ...

  5. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  6. Codeforces Round #722 (Div. 2)

    Codeforces Round #722 (Div. 2) 题号 题目 知识点 A Eshag Loves Big Arrays(题解略) 贪心 B Sifid and Strange Subseq ...

  7. Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训

    Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训 导语 涉及的知识点 题目 A Game B ...

  8. Codeforces Round #693 (Div. 3)A~G解题报告

    Codeforces Round #693 (Div. 3)A~G解题报告 A Cards for Friends 原题信息 http://codeforces.com/contest/1472/pr ...

  9. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

最新文章

  1. SAP WM初阶事务代码LX29 - List of Fixed Storage Bins
  2. 函数、指针、数组的组合 及结构体和共用体
  3. 定义快捷代码_nodepad++代码编辑器替代工具整理
  4. c#中hook的初次尝试
  5. 关于bash如何进行并发执行!
  6. mysql双主+keepalived【转】
  7. ALGO-84 大小写转换
  8. Spring后端接收表单方式上传的文件和数据
  9. 满怀希望,快乐坚强。
  10. Packet Tracer 思科模拟器入门教程 之九 路由器的基本配置
  11. BT5R3安装及汉化
  12. 如何在Google Play 当中使用ASO?google play aso
  13. Adobe Dreamweaver CS6(或者CC 2018.2 SP)安装失败解决方案
  14. 技术方案的讨论过程来看化繁为简
  15. 使用Guacamole实现远程桌面控制
  16. 不卷了!技术团队成员集体辞职
  17. 布兰迪斯大学计算机科学专业,布兰迪斯大学计算机科学专业
  18. 9 使用AD滴泪与敷铜
  19. MPChart饼图自定义图例
  20. 数据分析·零散知识点

热门文章

  1. Nginx如何支持HTTPS?手把手教会你每一步操作都贼简单,kafka和rabbitmq区别面试题
  2. 3dMax先蒙皮刷权重,再附加合并
  3. http://f.lefeng.com/u/36033580/detail/r/t/tid/1111
  4. vue 根据当前日期获取其前七天的日期
  5. 基于扩展有限元的多段压裂裂缝的扩展模拟(二)
  6. 边缘计算与算力网络综述
  7. IT项目管理 第七章 习题
  8. 服务器采购框架合同协议书范本,服务器采购框架合同协议书范本(12页)-原创力文档...
  9. mysql实现oracle的同义词_Oracle的同义词(synonyms)详解
  10. python上海交通大学出版社答案网_上海交通大学出版社python答案