【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
2017-02-21 13:04
417 查看
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了。
复杂度O(k*1024)。
复杂度O(k*1024)。
#include<cstdio> #include<cstring> using namespace std; int n,k,x,cnts[1110],tmpcnts[1110]; int main() { // freopen("c.in","r",stdin); int X; scanf("%d%d%d",&n,&k,&x); for(int i=1;i<=n;++i) { scanf("%d",&X); ++cnts[X]; } for(int i=1;i<=k;++i) { memset(tmpcnts,0,sizeof(tmpcnts)); int now=0; for(int j=0;j<=1023;++j) { int t=cnts[j]; if(now%2==0) { cnts[j]/=2; tmpcnts[j^x]+=(t-cnts[j]); } else { cnts[j]=(cnts[j]+1)/2; tmpcnts[j^x]+=(t-cnts[j]); } now+=t; } for(int j=0;j<=1023;++j) cnts[j]+=tmpcnts[j]; } for(int i=1023;i>=0;--i) if(cnts[i]) { printf("%d ",i); break; } for(int i=0;i<=1023;++i) if(cnts[i]) { printf("%d\n",i); break; } return 0; }
相关文章推荐
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number
- Codeforces Round #399 (Div. 1 + Div. 2, combined)C. Jon Snow and his Favourite Number
- 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1(DFS好题)
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) F
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A(贪心)
- 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E
- 【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1
- C. Jon Snow and his Favourite Number
- CodeForces 768C - Jon Snow and his Favourite Number 机智题
- CodeForces 768C Jon Snow and his Favourite Number 暴力 空间换时间