题解:P13683 【MX-X16-T1】「DLESS-3」XOR and Greater Sum

· · 题解

洛谷 P13683

题目大意:

给定 t 组数据,每一个数据包含一个 n,接下来有 n 个数,分别为每一个 a_i。对于每一组数据,如果可以通过选一些数异或和大于剩下的数的异或和,就输出 Yes,否则输出 No。

解题思路:

这道题很简单,只用判断全选后,异或和是否为 0。因为如果全选还不满足,不全选更不能满足。如果全选后异或和确实不为零,输出 Yes,否则输出 No。

AC 代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6+20;
int t, n;
int a[N];
signed main() {
    cin >> t;

    while (t--) {
        cin >> n;
        int sum = 0;

        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            sum ^= a[i];
        }

        if (sum == 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }

    return 0;
}