发现值域很小,而且怎么异或都不会超过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;
}

【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number的更多相关文章

  1. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number

    地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...

  2. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...

  3. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch

    地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...

  4. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...

  5. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)

    C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...

  6. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A B 水 搜索

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

    打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...

  8. 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs

    直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...

  9. 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1

    观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...

随机推荐

  1. CSS属性中cursor:hand

    在 IE 下设置鼠标为手型的方法: cursor: hand,但是在 FIREFOX 中是无效的,解决方法是在FIREFOX中设置: cursor: pointer. 而这个pointer 值在IE和 ...

  2. uva 11427

    题目大意:每天晚上你都玩纸牌,如果第一次赢了就高高兴兴地去睡觉:如果输了就接着玩,假设每盘游戏获胜的的概率都是p,且各盘游戏相互独立.你是一个固执的完美主义者,因此会一直玩到当晚获胜局数的比例严格大于 ...

  3. virtualbox网络相关

    前言 Baidu/google了n多次, 效果不佳. 网上说的都是比较老的virtualbox版本,有的是默认就bridge方式(2.2.0前), 有的不是bridge方式的,是通过工具uml-uti ...

  4. 网络知识===cookie 、session、JSESSIONID的区别

    cookie .session ? 让我们用几个例子来描述一下cookie和session机制之间的区别与联系.笔者曾经常去的一家咖啡店有喝5杯咖啡免费赠一杯咖啡的优惠,然而一次性消费5杯咖啡的机会微 ...

  5. 智联招聘的python岗位数据结巴分词(一)

    如何获取数据点击这里 下载之后的文件名为:all_results.csv 数据样式大概这样.然后下面我分析的是工作要求  也就是那边的绿框那一列. import csv import os impor ...

  6. [NOIP 2015] 斗地主 landlord

    想起几个月之前的 noip2015-只会瞎搞-这道题骗了 30 分.T T 题目 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的 A 到 K 加上大小王的共 54 张牌 ...

  7. unixbench安装使用

    UnixBench是一个类unix系(Unix,BSD,Linux)统下的性能测试工具,一个开源工具,被广泛用与测试linux系统主机的性能.Unixbench的主要测试项目有:系统调用.读写.进程. ...

  8. JS计算两个时间差的问题

    计算两个时间差的问题 function getDateIsMatching(){ var pactbegindate=$("#loanbegindate").datetimebox ...

  9. [ nginx ] 带宽下载限速

    nginx上了一个APP提供给用户下载,考虑到带宽占用的问题,决定在nginx上做下载限速处理. 操作系统:Centos6.7 X64 nginx版本:nginx/1.11.3 根据官方文档: 对ng ...

  10. WPF中使用WPFMediaKit视频截图案例

    前台 代码: <Window x:Class="WpfAppWPFMediaKit.MainWindow" xmlns="http://schemas.micros ...