列表

详情


NC216040. FourXor

描述

There is a sequence , you need to answer whether there are 4 integers satisfying and

The input guarantees that

Note: means the exclusive or of x and y

输入描述

The first line contains one single integer .

The second line contains integers .

The input guarantees that and .

输出描述

Output "Yes" if there are 4 integers satisfying the conditions, otherwise output "No".

示例1

输入:

5
1 2 3 4 5

输出:

Yes

示例2

输入:

5
1 2 4 8 16

输出:

No

示例3

输入:

5
1 3 4 8 9

输出:

No

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 223ms, 内存消耗: 16320K, 提交时间: 2022-04-29 17:20:51

T = int(input())
s = list(map(int, input().split()))
l = len(s)
for x in range(l):
    for y in range(x + 1, l):
        for z in range(y + 1, l):
            for w in range(z + 1, l):
                if s[x] ^ s[y] ^ s[z] ^ s[w] == 0:
                    print('Yes')
                    exit(0)
print('No')

C++(clang++11) 解法, 执行用时: 22ms, 内存消耗: 1676K, 提交时间: 2021-04-02 16:39:46

#include<bits/stdc++.h>
using namespace std;
int f[100005], a[100005],n;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for (int i=1;i<n;i++)
	for (int j=i+1;j<=n;j++)
	if (++f[a[i]^a[j]]==2){
		printf("Yes\n");
		return 0;
	}
		printf("No\n");
}

上一题