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 ...
随机推荐
- Struts2_day03讲义_使用Struts2完成对客户查询的优化操作
- Docker background
什么是 Docker? Docker 提供了一个可以运行你的应用程序的封套(envelope),或者说容器.它原本是 dotCloud 启动的一个业余项目,并在前些时候开源了.它吸引了大量的关注和讨论 ...
- Python函数相关
Python中的函数也是一种对象,而且函数还是一等公民.函数能作为参数,也能作为返回值,这使得Python中的函数变得很灵活.想想前面两篇中介绍的通过内嵌函数实现的装饰器和闭包. 下面就介绍一下Pyt ...
- php 安装rabbitmq扩展无报错版
需要安装rabbitmq-c,rabbitmq-c是一个用于C语言的,与AMQP server进行交互的client库.下载了v0.5.2版本(https://github.com/alanxz/ra ...
- Bypass X-WAF SQL注入防御(多姿势)
0x00 前言 X-WAF是一款适用中.小企业的云WAF系统,让中.小企业也可以非常方便地拥有自己的免费云WAF. 本文从代码出发,一步步理解WAF的工作原理,多姿势进行WAF Bypass. ...
- mysql相关攻击代码收集
1.批处理文件内容 @echo off net user li /add net user li /active:yes net localgroup Administrators li /add 2 ...
- Django 创建第一个项目
创建项目: [root@localhost ~]$ django-admin.py startproject web # web是项目名 [root@localhost ~]$ tree web/ w ...
- 执行automake时报错 error while making link: Operation not supported
执行automake时报错: [root@localhost project]# automake --add-missingconfigure.in: installing `./install-s ...
- 《转》win7 安装ujson 出现的“error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27”
本文转载自http://blog.csdn.net/Tilyp/article/details/72842800?locationNum=2&fps=1 我的python环境是 D:\work ...
- 虚拟机上的centos连不了外网,吧原来的配置信息改成如下就行(删除了一些多余的信息,变化:原来的ONBOOT的值是no)
DEVICE=eth1BOOTPROTO=dhcpHWADDR=08:00:27:67:be:98ONBOOT=yes