CF1805A.We Need the Zero
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an array a consisting of non-negative integers. You can choose an integer x and denote bi=ai⊕x for all 1≤i≤n, where ⊕ denotes the bitwise XOR operation. Is it possible to choose such a number x that the value of the expression b1⊕b2⊕…⊕bn equals 0?
It can be shown that if a valid number x exists, then there also exists x such that (0≤x<28).
有一个由非负整数构成的数组 a。你可以选择一个整数 x,并令对所有 1≤i≤n,有 bi=ai⊕x,其中 ⊕ 表示按位异或运算。是否存在某个数 x,使得表达式 b1⊕b2⊕…⊕bn 的值等于 0?
可以证明:若存在满足条件的 x,则必存在一个满足 0≤x<28 的 x。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). The description of the test cases follows.
The first line of the test case contains one integer n (1≤n≤103) — the length of the array a.
The second line of the test case contains n integers — array a (0≤ai<28).
It is guaranteed that the sum of n over all test cases does not exceed 103.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤103)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数——数组 a(0≤ai<28)。
保证所有测试用例的 n 之和不超过 103。
输出格式
For each set test case, print the integer x (0≤x<28) if it exists, or −1 otherwise.
对于每组测试用例,如果存在满足条件的整数 x(0≤x<28),则输出该整数 x;否则输出 −1。
输入输出样例
输入#1
5 3 1 2 5 3 1 2 3 4 0 1 2 3 4 1 2 2 3 1 1
输出#1
6 0 3 -1 1
说明/提示
In the first test case, after applying the operation with the number 6 the array b becomes [7,4,3], 7⊕4⊕3=0.
There are other answers in the third test case, such as the number 0.
在第一个测试用例中,对数组 b 应用数字 6 对应的操作后,数组变为 [7,4,3],且 7⊕4⊕3=0。
在第三个测试用例中还存在其他答案,例如数字 0。
输入解题思路,AI测评打分。不知道怎么写?