[codeforces 734F]Anton and School
2016-11-16 22:46
423 查看
【题目大意】给出长度为n(<=200000)的两个序列b和c,bc与a的关系如下图,求a
【解题思路】因为(a and b)+(a or b)=a+b,所以有Σa=(Σb+Σc)/(2*n),然后就可以通过a[i]=(b[i]+c[i]-Σa)/n求解
【呆马】
#include<cstdio> #include<algorithm> #include<cmath> #include<cstdlib> #include<iostream> using namespace std; const int N=200001; long long n,i,sum,B,C,j,k,a ,b ,c ,d ,s[30],bit[30]; void ns(){printf("-1"); exit(0);} int main() { scanf("%I64d\n",&n); for (i=1;i<=n;i++) scanf("%I64d",&b[i]); for (scanf("\n"),i=1;i<=n;i++) scanf("%I64d",&c[i]),d[i]=b[i]+c[i],sum+=d[i]; if (sum%(2*n)) ns(); sum/=2*n; for (i=1;i<=n;i++) { a[i]=d[i]-sum; if (a[i]%n) ns(); a[i]/=n; } for (s[0]=i=1;i<=29;i++) s[i]=s[i-1]<<1; for (i=1;i<=n;i++) for (j=a[i],k=0;k<=29;k++,j>>=1) bit[k]+=j&1; for (i=1;i<=n;i++) { B=C=0; for (j=a[i],k=0;k<=29;k++,j>>=1) if (j&1) B+=s[k]*bit[k],C+=s[k]*n; else C+=s[k]*bit[k]; if (B!=b[i] || C!=c[i]) ns(); } for (i=1;i<=n;i++) printf("%I64d ",a[i]); }
相关文章推荐
- 【codeforces 734F】Anton and School
- codeforces 785 D Anton and School - 2(组合数学)
- CodeForces 785 D.Anton and School - 2(组合数学)
- Codeforces 785D - Anton and School - 2(范德蒙恒等式+逆元)
- [刷题]Codeforces 785D - Anton and School - 2
- 数学(Anton and School,cf 734F)
- codeforces 785 D. Anton and School - 2
- cf 734F Anton and School
- Codeforces 785 D. Anton and School - 2
- 【codeforces 785D】Anton and School - 2
- CodeForces 785D Anton and School - 2 组合数学
- Codeforces-785D-Anton and School - 2(组合数学,范德蒙恒等式)
- Codeforces-785E-Anton and Permutation(分块区间查询,动态查询[l,r]内小于某个值的元素个数)
- CodeForces - 785C Anton and Fairy Tale(二分)
- Codeforces-734A-Anton and Danik(很水)
- 【组合数】【乘法逆元】 Codeforces Round #404 (Div. 2) D. Anton and School - 2
- CodeForces 785E Anton and Permutation 分块
- Codeforces Round #404 (Div. 2):D. Anton and School - 2(范德蒙德恒等式)
- CodeForces 785E Anton and Permutation 分块
- Codeforces Round #379 (Div. 2) F. Anton and School