Luogu P1469 Application of solving position / exclusive OR of finding chopsticks

Title link: https://www.luogu.com.cn/problem/P1469

Problem-solving ideas:
The sum of XOR of this question \ (n \) is the answer we are looking for.

The implementation code is as follows:

#include <bits/stdc++.h>
using namespace std;
int n, s, a;
int main() {
    scanf("%d", &n);
    while (n --) {
        scanf("%d", &a);
        s ^= a;
    }
    printf("%d\n", s);
    return 0;
}

Cin and Cout will pass the last group of TLE and change to scanf and printf.

Guess you like

Origin www.cnblogs.com/quanjun/p/12716450.html