【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
发现值域很小,而且怎么异或都不会超过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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【博弈论】【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> ...
- 【概率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 ...
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...
随机推荐
- [poj 3693]后缀数组+出现次数最多的重复子串
题目链接:http://poj.org/problem?id=3693 枚举长度L,看长度为L的子串最多能重复出现几次,首先,能出现1次是肯定的,然后看是否能出现两次及以上.由抽屉原理,这个子串出现次 ...
- BZOJ 4527: K-D-Sequence
4527: K-D-Sequence Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 163 Solved: 66[Submit][Status][D ...
- Kali Linux中前十名的Wifi攻击工具
无 线网络的攻与防一直是比较热门的话题,由于无线信号可以被一定范围内的任何人接收到(包括死黑阔),这样就给WIFI带来了安全隐患:路由器生产厂商和网 络服务供应商(ISPs)的配置大多是默认开启了WP ...
- HDU2819(二分图匹配,记录过程)
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- rtp包格式
转载一篇帮助我了解h264 rtp的文档,地址http://www.cppblog.com/czanyou/archive/2009/12/25/67940.html 当packetization-m ...
- 自动化测试===【转】Robot Framework作者建议如何选择自动化测试框架
原文:http://www.infoq.com/cn/news/2012/06/robot-author-suggest-autotest 软件自动化测试,作为手工测试的替代,越来越受到关注.Pekk ...
- bootstrap,ECMA
前端UI(布局)框架 bootstrap Amaze UI BootStrap 全局css样式 栅格系统 container 容器 超小屏幕 手机 vw <768px 宽度 100% 小屏幕 平 ...
- SQlServer的日期相减(间隔)datediff函数
select datediff(year, 开始日期,结束日期); --两日期间隔年 select datediff(quarter, 开始日期,结束日期); --两日期间隔季 select da ...
- [ Openstack ] Openstack-Mitaka 高可用之 Mariadb-Galera集群部署
目录 Openstack-Mitaka 高可用之 概述 Openstack-Mitaka 高可用之 环境初始化 Openstack-Mitaka 高可用之 Mariadb-Galera集群 ...
- 基于Docker 搭建 wordpress
在Docker中,一般遵循一个Docker只运行一个应用,这样方便维护. 首先需要将centos 镜像pull到本地,并搭建本地yum仓库 yum仓库地址:http://192.168.2.11:80 ...