【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
2024-08-31 01:37:41
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了。
复杂度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;
}
最新文章
- Linux及VMWare的网卡选择设计及理解
- 8.3 使用Fluent API进行属性映射【Code-First系列】
- HQL查询——HQL查询的基本用法
- bootstrap总结
- Ubuntu16.04 安装配置Caffe
- HTML DOM 对象简单介绍
- (准备写)URAL1824 Ifrit Bomber 题解
- Codeforces 677E Vanya and Balloons(DP + 一些技巧)
- linux系统下yum源的搭建
- 下拉菜单得经典写法html5
- c#对字符串的各种操作
- Berkeley DB基础教程
- gets函数完美替代
- 查看死锁原因 /data/anr/traces.txt
- 在Linux终端下使用代理访问网络(转)
- mybatis返回int类型报null
- OO第二单元作业分析
- SSH(Spring SpringMVC Hibernate)框架整合
- Use MusicBrainz in iOS(三)查询专辑的完整信息
- Linux 平台和 Windows平台下 Unicode与UTF-8互转
热门文章
- JAVA List 一边遍历一边删除元素
- API网关Kong部署和使用文档
- POJ1459:Power Network(多源点多汇点的最大流)
- C# Producer Consumer (生产者消费者模式)demo
- 【BZOJ】1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- autoKeras入门
- 【git】git提交忽略不必要的文件或文件夹
- How to learn wxPython
- WScript.Shell对象的 run()和exec()函数使用详解
- web页面的点对点复制粘贴