#include<cstdio> #include<cstring> #include<algorithm> usingnamespacestd; int n,ans1,ans2;
intmain(){ scanf("%d",&n); for (int i=1,x;i<=n;i++) scanf("%d",&x),ans1+=x; for (int i=1,x;i<=n;i++) scanf("%d",&x),ans2+=x; returnputs(ans1<ans2?"No":"Yes"),0; }
B. And
答案只可能是0,1,2,-1
依次判断即可
注意\(a_i \& x\)可能为0,贡献了两发WA……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<cstdio>
constint maxn=100005; int n,x,a[maxn],num[2][maxn]; intmain(){ scanf("%d%d",&n,&x); for (int i=1;i<=n;i++) scanf("%d",&a[i]),num[0][a[i]]++,num[1][a[i]&x]++; for (int i=0;i<=100000;i++) if (num[0][i]>1) returnputs("0"),0; for (int i=1;i<=n;i++){ num[0][a[i]]--; if (num[0][a[i]&x]) returnputs("1"),0; num[0][a[i]]++; } for (int i=0;i<=100000;i++) if (num[1][i]>1) returnputs("2"),0; returnputs("-1"),0; }