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 ...
随机推荐
- SQLServer------远程调用失败
1.情况 出现 2.解决方法 打开“控制面板” -> “卸载程序” -> 找到 “Microsoft SQL Server 2016) ExpressLocalDB”将其卸载 -> ...
- Dubbo -- 系统学习 笔记 -- 示例 -- 结果缓存
Dubbo -- 系统学习 笔记 -- 目录 示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 结果缓存 结果缓存,用于加速热门数据的访问速度,Dubbo提供声明式缓存,以减少用 ...
- SpringBoot thymeleaf模板版本,thymeleaf模板更换版本
SpringBoot thymeleaf模板版本 thymeleaf模板更换版本 修改thymeleaf模板版本 ================================ ©Copyright ...
- Echarts调整图表上下左右的间距,Echarts调整柱状图左右的间距
Echarts调整图表上下左右的间距,Echarts调整柱状图左右的间距 >>>>>>>>>>>>>>>> ...
- Redis 操作有序集合数据
Redis 操作有序集合数据: > zadd names "Tom" // zadd 用于往有序集合中添加元素,其中 1 在 Redis 中称为 score(分数),用来进行 ...
- 一个汉字转拼音的php类
代码来自网上,可用 <?php function Pinyin($_String, $_Code='gb2312') { $_DataKey = "a|ai|an|ang|ao|ba| ...
- react中的hoc和修饰器@connect结合使用
在学习react-redux的时候,看到了修饰器这个新的属性,这个是es7的提案属性,很方便.于是我用@connect代替了connect(使用的时候需要配置,这里不赘述),省去了很多不必要的代码,但 ...
- 关于控制台程序下使用mfc库中的函数时断言
例如: TCHAR path[8192]; int len = getmodulefilename(afxgetinstancehandle(),path,8192);//会出现断言 如果没有选择支持 ...
- Struts2(四)属性驱动和模型驱动
一.概述 所谓模型驱动,就是使用单独的JavaBean实例贯穿整个MVC流程,与之相对应的属性驱动方式,则使用属性作为贯穿MVC流程的信息携带者.属性无法独立存下,它必须依附于一个对象,这个对象就是A ...
- 【cs229-Lecture10】特征选择
本节课要点: VC维: 模型选择算法 特征选择 vc维:个人还是不太理解.个人的感觉就是为核函数做理论依据,低维线性不可分时,映射到高维就可分,那么映射到多高呢?我把可分理解为“打散”. 参考的资料: ...