Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)

Posted kanoon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)相关的知识,希望对你有一定的参考价值。

题目链接:https://codeforces.com/contest/1362/problem/B

题意

有一个大小及元素值均不超过 $1024$ 的正整数集合,求最小正整数 $k$,使得集合中的每个元素异或 $k$ 后得到的新集合与原集合相等,若这样的 $k$ 不存在输出 $-1$ 。

题解

数据范围较小,枚举即可。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    set<int> st1;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        st1.insert(x);
    }
    for (int k = 1; k <= 1024; k++) {
        set<int> st2;
        for (auto s : st1)
            st2.insert(s ^ k);
        if (st1 == st2) {
            cout << k << "
";
            return;
        }
    }
    cout << -1 << "
";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

以上是关于Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!

Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)

Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)

Codeforces Round #647 (Div. 2) D. Johnny and Contribution(BFS)