!-- Loading 底层遮罩 -->

P1469 找筷子

传送门

思路

异或满足交换律和结合律,可以找到大量成对数中找到落单数字。

代码

#include<iostream>
using namespace std;
int main(void)
{
    int n = 0, ans = 0, x = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        ans ^= x;
    }
    cout << ans;
    return 0;
}

 

posted @ 2022-03-30 21:19  Thinker-X  阅读(38)  评论(0)    收藏  举报