codechef july月赛 The Gray-Similar Code

http://www.codechef.com/JULY12/problems/GRAYSC/

The Gray-Similar Code

Problem code: GRAYSC

All submissions for this problem are available.

The Gray code (see wikipedia for more details) is a well-known concept.One of its important properties is that every two adjacent numbers have exactly one different digit in their binary representation.

In this problem, we will give you n non-negative integers in a sequenceA[1..n] (0<=A[i]<2^64), such that every two adjacent integers have exactly one different digit in their binary representation, similar to the Gray code.

Your task is to check whether there exist 4 numbers A[i1], A[i2], A[i3], A[i4] (1 <= i1 < i2 < i3 < i4 <= n) out of the givenn numbers such that A[i1] xor A[i2] xor A[i3] xor A[i4] = 0. Herexor is a bitwise operation which is same as ^ in C, C++, Java and xor in Pascal.

Input

First line contains one integer n (4<=n<=100000).Second line containsn space seperated non-negative integers denoting the sequence A.

Output

Output “Yes” (quotes exclusive) if there exist four distinct indices i1, i2, i3, i4 such thatA[i1] xor A[i2] xor A[i3] xor A[i4] = 0. Otherwise, output "No" (quotes exclusive) please.

Example

Input:

5
1 0 2 3 7


Output:

Yes



题意:  输入n个数  每2个相邻的数对应的二进制 只有其中的一位是不同的  问是否存在4个数 使得是个数抑或等于0




思路: 相邻的两个抑或肯定只剩下1位为1    相同为0 不同为1       所以如果数字够多的话得到的结果为2^0 2^1 2^3 .......2^64  如果数量大于2*64的话 一定会有重复的

那么2个重复的抑或等于0  所以当数量大于2*64  直接输出yes  否则暴力求解 即可

下面是标程

#include <cstdio>
 
#include <cstring>
 
#include <cstdlib>
 
#include <iostream>
 
using namespace std;
 
 
 
const int limit	=	64*2+10;
 
 
 
int main()
 
{
 
	int n;
 
	unsigned long long a[limit];
 
	cin >> n;
 
	if (n>=limit){
 
		puts("Yes");
 
		return 0;
 
	}
 
	for (int i=0;i<n;++i)
 
		cin >> a[i];
 
	for (int i=0;i<n;++i)
 
		for (int j=i+1;j<n;++j)
 
			for (int k=j+1;k<n;++k)
 
				for (int l=k+1;l<n;++l)
 
				if ((a[i]^a[j]^a[k]^a[l])==0){
 
					puts("Yes");
 
					return 0;
 
				}
 
	puts("No");
 
	return 0;
 
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值