[题目链接]
http://codeforces.com/problemset/problem/1013/B
[算法]
不难发现,答案只有0,1,2,-1,共4种取值
分类讨论即可,计算时可以使用STL-map
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXN 100010 int i,n,x; int a[MAXN]; map<int,int> mp; int main() { scanf("%d%d",&n,&x); for (i = 1; i <= n; i++) { scanf("%d",&a[i]); mp[a[i]]++; } for (i = 1; i <= n; i++) { if (mp[a[i]] >= 2) { printf("0 "); return 0; } } for (i = 1; i <= n; i++) { if ((a[i] & x) == a[i]) continue; if (mp[a[i] & x] >= 1) { printf("1 "); return 0; } } mp.clear(); for (i = 1; i <= n; i++) a[i] &= x; for (i = 1; i <= n; i++) mp[a[i]]++; for (i = 1; i <= n; i++) { if (mp[a[i]] >= 2) { printf("2 "); return 0; } } printf("-1 "); return 0; }