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
题目:
4 seconds
256 megabytes
standard input
standard output
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times:
- Arrange all the rangers in a straight line in the order of increasing strengths.
- Take the bitwise XOR (is written as
) of the strength of each alternate ranger with x and update it's strength.
Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following:
- The strength of first ranger is updated to
, i.e. 7.
- The strength of second ranger remains the same, i.e. 7.
- The strength of third ranger is updated to
, i.e. 11.
- The strength of fourth ranger remains the same, i.e. 11.
- The strength of fifth ranger is updated to
, i.e. 13.
The new strengths of the 5 rangers are [7, 7, 11, 11, 13]
Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him?
First line consists of three integers n, k, x (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) — number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively.
Second line consists of n integers representing the strengths of the rangers a1, a2, ..., an (0 ≤ ai ≤ 103).
Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.
5 1 2
9 7 11 15 5
13 7
2 100000 569
605 986
986 605
思路:因为每个数和异或后的数都很小,小于1024。所以可以用计数排序的思想来做。O(k*1024)。
这题找循环节也可以做。
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,k,x,sum[],tmp[]; int main(void)
{
cin>>n>>k>>x;
for(int i=,y;i<n;i++)
scanf("%d",&y),sum[y]++;
for(int i=;i<=k;i++)
{
for(int j=,t=;j<;t+=sum[j],j++)
if(t&)
{
tmp[j]+=(sum[j]+)/;
tmp[j^x]+=sum[j]/;
}
else
{
tmp[j^x]+=(sum[j]+)/;
tmp[j]+=sum[j]/;
}
memcpy(sum,tmp,sizeof(tmp));
memset(tmp,,sizeof(tmp));
}
for(int i=,ff=;i>=&&ff;i--)
if(sum[i]) printf("%d ",i),ff=;
for(int i=,ff=;i<=&&ff;i++)
if(sum[i]) printf("%d\n",i),ff=;
return ;
}
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) 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) C. Jon Snow and his Favourite Number
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...
随机推荐
- 修改Apache访问权限
You don't have permission to access / on this server.错误,居然说我此台服务器上无权限,ok解决办法如下: 找到:apache文件,进入conf文件 ...
- SQL语句,标准表达式中数据类型不匹配
id索引进行数据查询时提示错误! 标准表达式中数据类型不匹配. 两边的单引号去掉就好了,否则是在使用文本型. 改为:去掉两个单引号 ok,成功!
- zookeeper配置详解
原文地址: http://itindex.net/detail/40187-zookeeper-%E7%AE%A1%E7%90%86%E5%91%98-%E7%AE%A1%E7%90%86 参数名 说 ...
- 常用快捷键—Webstorm入门指南
提高代码编写效率,离不开快捷键的使用,Webstorm拥有丰富的代码快速编辑功能,你可以自由配置功能快捷键. 快捷键配置 点击“File”-> “settings” Webstorm预置了其他编 ...
- java基础---->Java中异常的使用(二)
这一篇博客用例子讲述一下异常的处理过程.那些 我们一直惴惴不安 又充满好奇的未来 会在心里隐隐约约地觉得它们是明亮的. 异常的执行过程 一.实例一:return语句 public class Exce ...
- 【BZOJ4295】[PA2015]Hazard 乱搞
[BZOJ4295][PA2015]Hazard Description 有n个人在轮流玩赌博机,一开始编号为i的人有a[i]元钱.赌博机可以抽象为一个长度为m的仅包含1和-1的序列,若抽到1,那么你 ...
- [Android Tips] 27. 检查 APK 是否可调试
使用 Android SDK 提供的 aapt 检查 APK 文件 $ aapt d badging ${APK_FILE} | grep 'application-debuggable' 检查自身 ...
- linux shell 脚本使用
定义变量 fileName=text.txt 变量名称fileName,变量名称text.txt 使用变量 $fileName 用美元符号$开头,后面加变量名称,即可使用变量 使用用户输入参数 打印第 ...
- Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程
一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module project 二.Maven聚合 在某个项目的p ...
- CentOS中文乱码问题的解决方法
一.CentOS系统访问 xxx.cn ,发现中文乱码于是用以前的方式:# yum -y install fonts-chinese # yum -y install fonts-ISO8859 Ce ...