CodeForces - 768C Jon Snow and his Favourite Number 桶排
https://vjudge.net/problem/CodeForces-768C
题意:n个数,k次操作,x。每次操作先排序,再让奇数位置上的数据a[i]:=a[i] XOR x; k<1e5,x<1e5,a[i]<1e3.
题解:由于每个数据为1~1000,且每次操作先排序,所以可以用桶排序维护所有数据。然后模拟操作(我自己模拟的一直wa,换了另一种才ac)。
网上另外也有人k%=64 然后暴力ac了,还有找循环节的也ac 了。
坑:第一次看codeforce 的数据,结果output answer看反了,用错误数据调试。
^x的过程中可能产生0,所以每个循环i=0开始。
i=maxn;while(--i)if(a[i]){cout<<i;break;}这句代码如果最大值是0不会输出。
做了好久。。。
ac代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn = ;
int a[maxn],a1[maxn]; int main() { int n, k, x;
cin >> n >> k >> x;
int q;
for (int i = ; i <= n; i++)scanf("%d", &q), a[q]++; while (k--) {
bool odd = ;
memset(a1, , sizeof(a1));
/*for (int i = 1; i <= maxn; i++) if (a[i]) {
//if(a[i]==1)i
int t;
if (a[i] % 2) {
if (odd)
t= (a[i] + 1) / 2, a[i] = (a[i] - t), a1[i^x]+=t;
else t = a[i] / 2, a[i] = (a[i] - t), a1[i^x]+=t;
odd = !odd;
}
else {
a[i] = a[i] / 2; a1[i^x] += a[i];
}
}
for (int i = 1; i <= maxn; i++) a[i] += a1[i]; }*/
int sum = ;
for (int i = ; i <= maxn; i++) {
if (sum & ) {
a1[i] += (a[i] + ) >> ;
a1[i^x] += a[i] >> ;
}
else {
a1[i] += a[i] >> ;
a1[i^x] += (a[i] + ) >> ;
}
sum += a[i]; }
for (int i = ; i <= maxn; i++) a[i] = a1[i];
}
int i = maxn;
for (int i = maxn; i >= ; i--) if (a[i]) {
cout << i << ' ';
break;
}
for (int i = ; i <= maxn; i++) if(a[i]){
cout << i;
break;
}
cin >> n;
/* cout << endl;
for (int i = 1; i <= maxn; i++) if (a[i]) {
//while(a[i]--)cout << i<<' ';
cout << a[i] << '*' << i << ' ';
//break;
}
cin >> n;*/
}
CodeForces - 768C Jon Snow and his Favourite Number 桶排的更多相关文章
- codeforces 768c Jon Snow And His Favourite Number
题意: 给出一个数列,和一种操作,以及两个数x和k. 这个操作有两个步骤: 首先把这个数列按照升序排序,然后把所有奇数位上的数字与x异或. 问执行k次操作之后,这个数列的最大值和最小值是多少. 思路: ...
- 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 ...
- Codeforces768C Jon Snow and his Favourite Number 2017-02-21 22:24 130人阅读 评论(0) 收藏
C. Jon Snow and his Favourite Number time limit per test 4 seconds memory limit per test 256 megabyt ...
- 【codeforces 768C】Jon Snow and his Favourite Number
[题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...
- Jon Snow and his Favourite Number CodeForces - 768C (技巧)
链接 题意 给定数组, 每次操作先将数组排序, 再将奇数位全部异或x, 求k次操作后数组最大值与最小值 (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) 题解 直接暴力模 ...
- codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)
题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...
- 【基数排序】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 ...
- C. Jon Snow and his Favourite Number DP + 注意数值大小
http://codeforces.com/contest/768/problem/C 这题的数值大小只有1000,那么可以联想到,用数值做数组的下标,就是类似于计数排序那样子.. 这样就可以枚举k次 ...
- Codeforces I. Producing Snow(优先队列)
题目描述: C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- GoF--适配器设计模式
1.概念: 适配器模式(Adapter Pattern)把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作. 2.形式 a.类的适配器模式 ...
- ARM入门最好的文章
一 首先说说arm的发展 可以用一片大好来形容,翻开各个公司的网站,招聘里面嵌入式占据了大半工程师职位.广义的嵌入式无非几种:传统的什么51.avr.pic称做嵌入式微控制器:arm是嵌入式微处理器 ...
- JavaScript Promise迷你书(中文版)
最近,发现了一个很不错的关于Promise介绍的迷你电子版书,分享给大家: http://liubin.org/promises-book/#chapter4-advanced-promise (篇幅 ...
- 网络编程之HttpClient类(转)
12.2 网络编程之HttpClient类 除了可以使用HttpWebRequest类来实现HTTP网络请求之外,我们还可以使用HttpClient类来实现.对于基本的请求操作,HttpClient类 ...
- Qt编写的RTSP播放器+视频监控(ffmpeg版本)
记得四年前就写了个简易版本的,当时写得非常粗糙,代码实在惨不忍睹,时隔多年后,重新写了个版本,同时还解决了以前不支持6画面8画面切换等异形布局的问题.1:可以用过目录下的rtsp.txt设置要显示的视 ...
- webstorm启动报错
环境: 在重装完系统的电脑上第一次安装webstorm, 问题: 解决”failed to load jvm dll“的报错问题: 解决方案: 安装Microsoft Visual C++ 2010 ...
- 第二步 (仅供参考) sencha touch 使用cmd打包apk
最新版本的cmd可以直接将sencha touch项目打包成本地应用,不过还有很多不足,本文仅供参考 通过sencha app build native命令可以直接将项目打包成本地应用,不过在命令运行 ...
- MySQL的ALTER变更、正则查询、分组查询、排序查询以及事务查询的概
MySQL的表和字段信息的变更 ALTER TABLE table-name DROP column-name; #删除某个字段 ALTER TABLE table-name ADD column-n ...
- 【咸鱼教程】EUI多图片滑动组件ScrollView
先看看实际效果 实现原理1. ScrollView继承eui.Scroll2. 监听eui.Sroll的CHANGE_START和CHANGE_END事件, 根据鼠标滑动距离,来改变视口 ...
- java 程序运行的基础知识【Java bytecode】
聊聊文字,写一篇关于 java 基础知识的博文. JVM 线程栈 到 函数运行 每一个JVM线程来说启动的时候都会创建一个私有的线程栈.一个jvm线程栈用来存储栈帧,jvm线程栈和C语言中的栈很类似, ...