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 ...
随机推荐
- Cocos2d-js异步图片加载
这里说的是在需要的使用加载图片,比如游戏中的某个关卡的图片,不用在游戏一开始就加载(万一用户玩不到那关,岂不是很冤,流量费了那么多),否则 载入速度也慢.这种方式加载资源要用到cc.loader官方文 ...
- idea 破解注册方法总结
注册码(无期限) JetbrainsCrack-2.6.2.jar适用于ideaIU-2017.2.之前版本,若版本较新适用 JetbrainsCrack-2.6.3_proc.jar. 其中Jetb ...
- ios实现倒计时的两种方法
方法1:使用NSTimer来实现 主要使用的是NSTimer的scheduledTimerWithTimeInterval方法来每1秒执行一次timeFireMethod函数,timeFireMeth ...
- 命令行唤起xcode模拟器
1.IOS模拟器列表获取命令 xcrun instruments -s 2.IOS启动模拟器命令 xcrun instruments -w "iPhone 8 (12.1)"
- 解决ubuntu没有/var/log/messages的问题
1:root身份打开 /etc/rsyslog.d/50-default.conf 2:把注释#去掉 #*.=info;*.=notice;*.=warn;\ # auth,authpriv.none ...
- get all sites under IIS
https://stackoverflow.com/questions/2555668/how-to-programmatically-get-sites-list-and-virtual-dirs- ...
- html5--6-68 实战前的准备工作:了解HTML5大纲算法
html5--6-68 实战前的准备工作:了解HTML5大纲算法 学习要点 了解HTML5大纲算法 在html5中有一个很重要的概念,叫做HTML5大纲算法(HTML5 Outliner),它的用途为 ...
- GCD基础知识
并行和并发 在英文世界里,「并行」和「并发」的区别比较清晰,「并行」对应parallelism,「并发」对应concurrency:但在中文世界里二者仅一字之差,两个概念非常容易弄混淆: 各种资料对「 ...
- 哈希表的C实现(二)
上次大致分析了一下哈希表的链地址法的实现,今天来分析一下另一种解决哈希冲突的做法,即为每个Hash值,建立一个Hash桶(Bucket),桶的容量是固定的,也就是只能处理固定次数的冲突,如104857 ...
- View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications
Responding to Display-Related Notifications 响应跟显示相关的通知 When the visibility of a view controller’s vi ...