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 ...
随机推荐
- SpringIoc 和 工厂模式(反射实现)
一.先演示 “简单工厂”: package org; interface Fruit { public void eat(); } class Apple implements Fruit { pub ...
- Vue 基本用法
Vue的基本用法 模板语法{{ }} 关闭掉 django中提供的模板语法{{ }} 指令系统 v-text v-html v-show和v-if v-bind和v-on v-for v-model ...
- mysql-7事务管理
1.事务的使用场景 mysql事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人愿,你既需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数 ...
- 交叉编译OpenCV的Android版本
交叉编译OpenCV的Android版本 OpenCV作为一个强大的图像处理库,在Android上也有强大的应用. OpenCV官网提供了SDK的下载,可以直接下载使用 OpenCV官网地址:http ...
- 分布式锁实践(二)-ZooKeeper实现总结
写在最前面 前几周写了篇 利用Redis实现分布式锁 ,今天简单总结下ZooKeeper实现分布式锁的过程.其实生产上我只用过Redis或者数据库的方式,之前还真没了解过ZooKeeper怎么实现分布 ...
- Selenium2+python自动化64-100(大结局)[已出书]
前言 小编曾经说过要写100篇关于selenium的博客文章,前面的64篇已经免费放到博客园供小伙伴们学习,后面的内容就不放出来了,高阶内容直接更新到百度阅读了. 一.百度阅读地址: 1.本书是在线阅 ...
- ImportError: Couldn't import Django.或者提示Django 模块不存在
ImportError: Couldn't import Django. 或者 多版本的python引起的,执行以下命令 即可解决问题 python3是新的版本的python python3 -m ...
- 通过nginx + lua来统计nginx上的监控网络请求和性能
介绍 以前我们为nginx做统计,都是通过对日志的分析来完成.比较麻烦,现在基于ngx_lua插件,开发了实时统计站点状态的脚本,解放生产力. 项目主页: https://github.com/sky ...
- OpenCv dnn module -实时图像分类
配置环境:OpenCv3.4, vs2013(x64),Win7.用OpenCv dnn module 实时检测摄像头,视频和图像的分类示例原代码为:https://docs.opencv.org/3 ...
- 使用opencv3+python实现视频运动目标检测
本文主要实现了伯乐在线上的一个实践小项目,原文链接,用以巩固opencv视频操作知识内容.整个项目均有代码注释,通俗易懂,短短几十行就可以达到还算不错的实现效果,做起来成就感满满哒.打开编辑器,一起来 ...