C. Jon Snow and his Favourite Number DP + 注意数值大小
http://codeforces.com/contest/768/problem/C
这题的数值大小只有1000,那么可以联想到,用数值做数组的下标,就是类似于计数排序那样子。。
这样就可以枚举k次操作,然后for (int i = 0; i <= 1025; ++i),也就是O(1000 * k)的复杂度而已。
0--1000中任选两个数异或,最大值是1023
然后注意下只有奇数位异或,dp[now][val]计数转移下去就好了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + ;
int a[maxn];
vector<int>vc[maxn];
map<pair<int, int>, int>pos;
int dp[][ + ];
int f(int val) {
return (val + ) / ;
}
void work() {
int n, k, x;
cin >> n >> k >> x;
for (int i = ; i <= n; ++i) {
cin >> a[i];
dp[][a[i]]++;
}
int now = ;
for (int i = ; i <= k; ++i) {
now = !now;
memset(dp[now], , sizeof dp[now]);
int L = , R = ;
for (int j = ; j <= ; ++j) {
if (dp[!now][j]) {
R = L + dp[!now][j] - ;
int has = f(R) - f(L - );
dp[now][j ^ x] += has;
dp[now][j] += dp[!now][j] - has;
L = R + ;
}
}
assert(L == n + );
}
int mi = inf, mx = -inf;
for (int i = ; i <= ; ++i) {
if (dp[now][i]) {
mi = min(i, mi);
mx = max(i, mx);
}
}
cout << mx << " " << mi << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
C. Jon Snow and his Favourite Number DP + 注意数值大小的更多相关文章
- 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 ...
- 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 ...
- codeforces 768c Jon Snow And His Favourite Number
题意: 给出一个数列,和一种操作,以及两个数x和k. 这个操作有两个步骤: 首先把这个数列按照升序排序,然后把所有奇数位上的数字与x异或. 问执行k次操作之后,这个数列的最大值和最小值是多少. 思路: ...
- CodeForces - 768C Jon Snow and his Favourite Number 桶排
https://vjudge.net/problem/CodeForces-768C 题意:n个数,k次操作,x.每次操作先排序,再让奇数位置上的数据a[i]:=a[i] XOR x; k< ...
- Jon Snow and his Favourite Number CodeForces - 768C (技巧)
链接 题意 给定数组, 每次操作先将数组排序, 再将奇数位全部异或x, 求k次操作后数组最大值与最小值 (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) 题解 直接暴力模 ...
- 【基数排序】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 ...
- 【codeforces 768C】Jon Snow and his Favourite Number
[题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...
- codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)
题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...
- Codeforces Round #265 (Div. 1) C. Substitutes in Number dp
题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...
随机推荐
- A JavaScript library for reading EXIF meta data from image files.
exif-js/exif-js: JavaScript library for reading EXIF image metadata https://github.com/exif-js/exif- ...
- pyspark 连 MongoDB复制集
解决问题思路: 核心:0-理解pyspark的执行与java jar的关系: 1-看控制台,看日志: 2-jar缺不缺,版本号,放哪里. [root@hadoop1 mylocalRepository ...
- Maven group, artifact or version defined in the pom file do not match the file ...
在把library上传到bintray空间的时候报以下错误 Could not upload to 'https://api.bintray.com/content/ping/maven/comm-a ...
- ie下文件上传无权访问的问题
最近项目遇到个问题,ie下文件上传无权访问,在网上找了很久才找到答案,原来是因为ie下不能用js触发input=file的点击事件,必须手动点击才可以.
- bzoj4103: [Thu Summer Camp 2015]异或运算
对于每个询问暴力枚举x~y,然后在Trie去找第k大,开始我写了个二分答案然后算比当前答案大的个数,打了个第10个点的表就跑出19s+比bzoj垫底还慢4s+ 然而不用二分,直接1000个点一起在树上 ...
- 织梦DEDE多选项筛选_联动筛选功能的实现_二次开发
织梦默认的列表页没有筛选功能,但有时候我们做产品列表页的时候,产品的字段比较多,很多人都需要用到筛选功能,这样可以让用户更方便的找到自己所需要的东西,实现这个联动筛选功能需要对织梦进行二次开发,下面就 ...
- Java 通过 HTTP 下载文件
1. [代码]Download.java package core.spider; import java.io.*;import java.net.*;import java.util.*; / ...
- Oracle中如何用SQL检测字段是否包括中文字符
用Oracle的编码转换的函数Convert实现,测试后可行. SQL> select * 2 from (select 'abcd' c1 from dual 3 ...
- 书写优雅的shell脚本(三) - shell中exec解析
参考:<linux命令.编辑器与shell编程> <unix环境高级编程> exec和source都属于bash内部命令(builtins commands),在bash下输入 ...
- 替换一个文件中的内容BAT
@echo off setlocal enabledelayedexpansion set file=%1set "file=%file:"=%" for %%i in ...