洛谷P1469 找筷子 题解 位运算/异或的应用

题目链接:https://www.luogu.com.cn/problem/P1469

解题思路:
这道题目 \(n\) 个数的异或和就是我们要找的答案。

实现代码如下:

#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、cout竟然会TLE最后一组、改成scanf和printf就过了。

posted @ 2020-04-16 22:43  quanjun  阅读(177)  评论(0编辑  收藏  举报