Xor Sum Gym - 100741D (異或超水題)

題目鏈接:https://vjudge.net/problem/Gym-100741D

題意:求n個數中出現次數爲奇數次的所有數的異或值。

思路:水題,同一個值,異或兩次相當於沒有進行異或,所以不用求出現次數爲奇數還是偶數,直接全部異或就行。

代碼如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<sstream>
#include<deque>
#include<stack>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-6;
const int  maxn = 1e6 + 50;
const int  maxt = 300 + 10;
const int mod = 10;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int Dis[] = {-1, 1, -5, 5};
const int inf = 0x3f3f3f3f;
const int MOD = 1000;
int n, m, k;
int main(){
    int n;
    scanf("%d", &n);
    int ans;
    scanf("%d", &ans);
    int x;
    for(int i = 1; i < n; ++i){
        scanf("%d", &x);
        ans ^= x;
    }
    printf("%d\n", ans);
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章