Codeforces768C Jon Snow and his Favourite Number 2017-02-21 22:24 130人阅读 评论(0) 收藏
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
using namespace std;
int cnt[2][2005];
int n,k,m; int main()
{
int x;
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(cnt,0,sizeof(cnt)); for(int i=0; i<n; i++)
{
scanf("%d",&x);
cnt[0][x]++;
}
for(int i=0; i<m; i++)
{
bool flag=0;
for(int j=0; j<2000; j++)
{
if(cnt[0][j]>0||cnt[1][j]>0)
{
if(cnt[0][j]%2==0)
{
int s=j^k;
if(s<=j)
cnt[0][s]+=cnt[0][j]/2;
else
cnt[1][s]+=cnt[0][j]/2;
cnt[0][j]/=2;
cnt[0][j]+=cnt[1][j];
cnt[1][j]=0;
}
else
{
int s=j^k;
if(flag==0)
{
if(s<=j)
cnt[0][s]+=cnt[0][j]/2+1;
else
cnt[1][s]+=cnt[0][j]/2+1;
cnt[0][j]/=2;
cnt[0][j]+=cnt[1][j];
cnt[1][j]=0;
flag=1;
}
else
{
if(s<=j)
cnt[0][s]+=cnt[0][j]/2;
else
cnt[1][s]+=cnt[0][j]/2;
cnt[0][j]/=2;
cnt[0][j]++;
cnt[0][j]+=cnt[1][j];
cnt[1][j]=0;
flag=0;
} }
}
}
}
int mn,mx;
for(int i=0;i<=2000;i++)
{
if(cnt[0][i]>0)
{
mn=i;
break;
}
}
for(int i=2000;i>=0;i--)
{
if(cnt[0][i]>0)
{
mx=i;
break;
}
}
printf("%d %d\n",mx,mn);
}
return 0;
}
Codeforces768C Jon Snow and his Favourite Number 2017-02-21 22:24 130人阅读 评论(0) 收藏的更多相关文章
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- Codeforces805D. Minimum number of steps 2017-05-05 08:46 240人阅读 评论(0) 收藏
D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...
- 周赛-The Number Off of FFF 分类: 比赛 2015-08-02 09:27 3人阅读 评论(0) 收藏
The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Number Sequence 分类: HDU 2015-06-19 20:54 10人阅读 评论(0) 收藏
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- Number of Containers(数学) 分类: 数学 2015-07-07 23:42 1人阅读 评论(0) 收藏
Number of Containers Time Limit: 1 Second Memory Limit: 32768 KB For two integers m and k, k is said ...
- HDU1349 Minimum Inversion Number 2016-09-15 13:04 75人阅读 评论(0) 收藏
B - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- ZOJ 3702 Gibonacci number 2017-04-06 23:28 28人阅读 评论(0) 收藏
Gibonacci number Time Limit: 2 Seconds Memory Limit: 65536 KB In mathematical terms, the normal ...
- 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) C. Jon Snow and his Favourite Number
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...
随机推荐
- java 题
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1 ...
- spring 配置文件中使用properties文件 配置
配置Bean载入properties文件: <bean id="propertyPlaceholderConfigurer" class="org.springfr ...
- KMP算法解释
给定两个字符串A,B,判断T是否为S的子串(变式:寻找子串B在串A中的位置). 要求一个O(|A|+|B|)的做法. 通常称A为目标串(或主串),B为模式串. 算法过程: 我们假设串A的长度为n,串B ...
- [转][Java]自定义标签简介
作用:自定义标签主要用于移除 jsp 页面中的 java 代码. 实现:需要完成以下两个步骤: 编写一个实现 Tag 接口的 Java 类,把页面 java 代码移到这个 java 类中.(标签处理类 ...
- [html][javascript]父子窗体传值
父窗体 <script type="text/javascript"> newwindow = window.open("b1.html",&quo ...
- 停止调试 IIS 不退出
在VS主面板打开:工具->选项->调试->编辑继续 取消选中[启用"编辑并继续"] 就可以(不过这是针对所有的调试). 若只想对单个项目进行设置,可以选择自己 ...
- django-常用过滤器
django常用过滤器 add :字符串相加,数字相加,列表相加,如果失败,将会返回一个空字符串. default:提供一个默认值,在这个值被django认为是False的时候使用.比如:空字符串.N ...
- OpenMP Hello World
▶ OpenMP 环境配置,第一个程序 ▶ OpenMP 在Visual Studio 2015 中的配置 ● VS项目属性右键,属性,C/C++,语言,OpenMP支持,选择是(/openmp). ...
- Ubuntu无法sudo提权,报当前用户不在sudoers文件中错误
Ubuntu安装后默认root不能登陆系统,密码也是随机生成,其他用户使用root权限,可以使用sudo提权,前提是该用户在/etc/sudoers配置列表中. 但是有时用户名从/etc/sudoer ...
- 错误:HttpServlet was not found on the Java
我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on t ...