标签:for code c++ com scanf space tin scan ace
[题目链接]
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\n"); return 0; } } for (i = 1; i <= n; i++) { if ((a[i] & x) == a[i]) continue; if (mp[a[i] & x] >= 1) { printf("1\n"); 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\n"); return 0; } } printf("-1\n"); return 0; }
标签:for code c++ com scanf space tin scan ace
原文地址:https://www.cnblogs.com/evenbao/p/9393366.html