C. Jon Snow and his Favourite Number
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  1. Arrange all the rangers in a straight line in the order of increasing strengths.
  2. 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:

  1. The strength of first ranger is updated to ,
    i.e. 7.
  2. The strength of second ranger remains the same, i.e. 7.
  3. The strength of third ranger is updated to ,
    i.e. 11.
  4. The strength of fourth ranger remains the same, i.e. 11.
  5. 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?

Input

First line consists of three integers nkx (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

Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.

Examples
input
5 1 2
9 7 11 15 5
output
13 7
input
2 100000 569
605 986
output
986 605

—————————————————————————————————————
题目的意思是把一组数从小到大排列,奇数位与给定的数异或,重复m次,问最后最大的数和最小的数

可以找循环节,因为数字小也可以纯暴力跑。


#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) 收藏的更多相关文章

  1. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  2. 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 ...

  3. 周赛-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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 【基数排序】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 ...

随机推荐

  1. 关于 javascript:void(0) 的问题.

    原文地址:楚广明的博客 http://www.cnblogs.com/chu888chu888/archive/2012/01/05/2313045.html 最近看了好几个关于<a>标签 ...

  2. 【free() invalid next size】谨慎地在C++的类中存储指针来方便访问其他节点

    “我跟你们说,你们知道STL容器,vector/string/deque等等,都有个reserve方法吗?你们一个个地push_back,嫌C++比C慢,怪谁?” “要像我这样,预先分配足够大的空间, ...

  3. post参数的方法 json data 和特别的传参

    json格式传参: 那么久使用json的方式传参: json=payload data格式传参: 其他方式传参: 在webFormes里 value 的值不是普通的字符 要把value值先序列化在放入 ...

  4. 【HDU】4352 XHXJ's LIS(数位dp+状压)

    题目 传送门:QWQ 分析 数位dp 状压一下现在的$ O(nlogn) $的$ LIS $的二分数组 数据小,所以更新时直接暴力不用二分了. 代码 #include <bits/stdc++. ...

  5. Android开发入门——Button绑定监听事件三种方式

    import android.app.Activity; import android.os.Bundle;import android.view.View;import android.widget ...

  6. 并发包学习(一)-Atomic包小记

    此篇是J.U.C学习的第一篇Atomic包相关的内容,希望此篇总结能对自己的基础有所提升.本文总结来源自<Java并发编程的艺术>第七章并配以自己的实践理解.如有错误还请指正. 一.案例分 ...

  7. CentOS7入门到精通实战课程课后习题

    Linux自动化运维系列①: CentOS7入门到精通实战--->传送门 http://edu.51cto.com/course/13055.html 01.系统入门课后习题 1.口述一个命令执 ...

  8. Django框架之模板语法【转载】

    Django框架之模板语法 一.什么是模板? 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法分类 一.模板语法之变量:语法为 {{ }}: 在 Django ...

  9. 当前触发事件的两种方式(onclick) 和 ('id') 获取

    1. <input type='text' onclick = 'Clickon(this)'> <script> function Clickon(num){ num.sty ...

  10. Mysql 索引优化 - 1

    单表  范围查询 后面的索引会失效 双表  左右连接建立索引互相使用 三表   用小结果集驱动大表结果, 先优化括号里面的SQL, 保证JOIN被驱动的表上ON字段有索引 索引失效(常见原因) 全职匹 ...