其他分享
首页 > 其他分享> > 1362B - Johnny and His Hobbies

1362B - Johnny and His Hobbies

作者:互联网

暴力:

依题意暴力枚举即可

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1030;
int n;
int a[N],b[N];
int main () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n;
		for (int i = 1;i <= n;i++) cin >> a[i];
		sort (a+1,a+1+n);
		int ans = -1;
		for (int i = 1;i <= 1024;i++) {
			for (int j = 1;j <= n;j++) b[j] = a[j]^i;
			sort (b+1,b+1+n);
			bool flag = true;
			for (int j = 1;j <= n;j++) {
				if (a[j] != b[j]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				ans = i;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

标签:std,His,暴力,Johnny,int,cin,Hobbies,include,题意
来源: https://www.cnblogs.com/incra/p/16389912.html