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. [java] java 实现FTP服务器文件的上传和下载

    利用Apache commons-net 实现: package com.xwolf.driver.util; import com.xwolf.driver.exception.RunExcepti ...

  2. Linux wc指令解析

    wc指令比较实用,可以统计文件中的字节数.字符数.行数.字数等. 先通过 wc --help 查看指令帮助. $ wc --help Usage: wc [OPTION]... [FILE]... o ...

  3. Oracle本地网络服务名配置

    1.安装Oracle 11G Client后可以在开始菜单中找到 选择NETCA->本地网络服务名配置 选择添加本地网服务名配置 这里的服务名:指的是也就是数据库名 在网络中架设C/S 客户端选 ...

  4. 使用libssh2连接到远程服务器

    libssh2-1.7.0.tar.gz  示例代码:libssh2-1.7.0.tar.gz\libssh2-1.7.0\example 官网示例 https://www.libssh2.org/e ...

  5. bootstrap插件的一些常用属性介绍

    1.下拉菜单 <div class="dropdown"> <button class="btn btn-default dropdown-toggle ...

  6. uedit富文本编辑器及图片上传控件

    微力后台 uedit富文本编辑器及文件上传控件的使用,无时间整理,暂略,参考本地代码.能跑起来.

  7. django-url命名空间+反查

    from django.conf.urls import url, include urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^h ...

  8. 消息队列kafka

    消息队列kafka   为什么用消息队列 举例 比如在一个企业里,技术老大接到boss的任务,技术老大把这个任务拆分成多个小任务,完成所有的小任务就算搞定整个任务了. 那么在执行这些小任务的时候,可能 ...

  9. JDK8时间格式转换

    来源:https://blog.csdn.net/zhangzijiejiayou/article/details/76597329 LocalDateTime 本地日期时间 LocalDateTim ...

  10. How to Integrate JCaptcha in Spring Security

    The repository for JCaptcha is this one: <repository> <id>sourceforge-releases</id> ...