Description

Mr. AngelClover just learnt XOR on his Computer Class. XOR is a bit arithmetic operator that returns one value if one, but not both, of its operands is one. It is also called Exclusive-OR. Now Mr. AngelClover wonders if it is possible to pick up some numbers from a certain number set, such that the result of Exclusive-OR is zero. And he wants the numbers to be as few as possible but there should be at least one.
Can you help him?

Input

The first line is a positive integer N, which means the number of the number set. And there are N lines followed, in each there is a single positive integer, which is the number in the set. Each number in the set is an integer between 0 and 2^16 inclusive. 0< N <=30. (Please use standard input, and don’t read or write files.)

Output

There is only one line in the output, which is the smallest number as described above. If Mr. AngelClover can NOT find such numbers after XOR is zero, output -1. (Please use standard output, and don’t read or write files.)

Sample Input

4
1
2
3
4

Sample Output

3

Hint

Numbers which are picked up are 1, 2, 3.

For 40% input data cases, N <= 15.

Source

NKPC5

题目意思就是选几个数进行异或运算结果为0的最小个数 。一开始用觉得数据不大,用深搜果断超时。

后来想想觉得应该让个数最小深搜会产生大量没用的结果而且要全部遍历,改用广搜。

 #include <stdio.h>
#include <iostream>
#include <queue>
using namespace std; int n;
int a[];
int ans; struct Node{
int val;
int step;
int bs;
}; int bfs(){
queue<Node> Q;
Node n1;
n1.val=;
n1.step=;
n1.bs=;
Q.push(n1);
while(!Q.empty()){
Node now=Q.front();
Q.pop();
for(int i=now.bs; i<n; i++){
int v=a[i]^now.val;
if(v==)return now.step+;
else{
Node n2;
n2.val=v;
n2.step=now.step+;
n2.bs=i+;
Q.push(n2);
}
}
}
return -;
} int main(int argc, char *argv[])
{
while( scanf("%d",&n)!=EOF ){
for(int i=; i<n; i++){
scanf("%d",&a[i]);
}
ans=bfs();
printf("%d\n",ans);
}
return ;
}

TOJ 3176 Challenge from XOR的更多相关文章

  1. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  2. 最小生成树 TOJ 4117 Happy tree friends

    链接http://acm.tju.edu.cn/toj/showp4117.html 4117.   Happy tree friends Time Limit: 1.0 Seconds   Memo ...

  3. Codechef April Challenge 2019 游记

    Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\ ...

  4. CodeChef April Challenge 2019题解

    传送门 \(Maximum\ Remaining\) 对于两个数\(a,b\),如果\(a=b\)没贡献,所以不妨假设\(a<b\),有\(a\%b=a\),而\(b\%a<a\).综上, ...

  5. 【CodeChef】December Challenge 2019 Div1 解题报告

    点此进入比赛 这次比赛本来想好好打的,但不幸的是,这周先是要认真复习准备月考,考完又是发烧在床上躺了一个周末,所以最终没能打完. 我还是好弱啊. \(T1\):Binary XOR(点此看题面) 大致 ...

  6. Codechef October Challenge 2019 Division 1

    Preface 这次CC难度较上两场升高了许多,后面两题都只能借着曲明姐姐和jz姐姐的仙气来做 值得一提的是原来的F大概需要大力分类讨论,结果我写了一大半题目就因为原题被ban了233 最后勉强涨了近 ...

  7. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  8. 二分+DP+Trie HDOJ 5715 XOR 游戏

    题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  9. BZOJ 2115 【Wc2011】 Xor

    Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 ...

随机推荐

  1. 原型(Prototype)模式

    一. 原型(Prototype)模式 原型模式的用意是:通过给出一个原型对象来指明所要创建的对象类型,然后用复制这个原型对象的办法创建出更多的同类型对象. 从孙大圣的手段谈起 孙悟空在与黄风怪的战斗中 ...

  2. 20145218张晓涵 PC平台逆向破解_advanced

    ---恢复内容开始--- 20145218张晓涵 PC平台逆向破解_advanced shellcode注入 基础知识 shellcode就是在利用溢出攻击溢出时要值入的代码,也就是溢出后去执行的代码 ...

  3. vue记住密码功能

    话不多说,直接上代码. html部分: <el-form :model="ruleForm2" :rules="rules2" ref="rul ...

  4. MVC5中 在更新 Microsoft.Aspnet.Identity 后编译器错误

    环境:vs2013预览版chs,我试着创建vb.net web应用,从对话框中选择MVC和WebAPI.编译ok了.通过NuGet管理器更新了Microsoft.Aspnet.Identity.Cor ...

  5. Redis 占用Windows系统盘空间23G

    Redis常出现问题总结: 1.当出现修改--maxheap and --heapdir 在启动这两个版本时都会创建一个 RedisQFork.dat文件,我不确定 RedisQFork 文件是否变小 ...

  6. WPF 控件库——仿制Chrome的ColorPicker

    WPF 控件库系列博文地址: WPF 控件库——仿制Chrome的ColorPicker WPF 控件库——仿制Windows10的进度条 WPF 控件库——轮播控件 WPF 控件库——带有惯性的Sc ...

  7. EFCore扩展Select方法(根据实体定制查询语句)

    EFCore扩展Select方法(根据实体定制查询语句)  通常用操作数据库的时候查询返回的字段是跟 我们的定义的实体是不一致的,所以往往针对UI或者接口层创建大量的Model, 而且需要手动对应字段 ...

  8. vi/vim使用总结

    第一部份:一般模式可用的按钮说明,光标移动.复制粘贴.搜索取代等 移动光标的方法: h 或 向左箭头键(←) 光标向左移动一个字符 j 或 向下箭头键(↓) 光标向下移劢一个字符 k 或 向上箭头键( ...

  9. Linux常用命令--用户管理,文件权限,打包命令等

    幕布链接 Linux常用命令--用户管理,文件权限,打包命令等

  10. 再谈VS2010编译更高平台vs2012(v110),vs2015(v140)的objectARX程序

    前段时间我贴了一篇vs2010批量编译vc6~vs2008的ARX版本,实际上那一篇是我在研究vs2010编译v110,v140平台的附带收获,正应了那句话,有心栽花花不开,无心插柳柳成荫,因为vs2 ...