洛谷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就过了。

猜你喜欢

转载自www.cnblogs.com/quanjun/p/12716450.html
今日推荐