【codeforces 768C】Jon Snow and his Favourite Number
来源:互联网 发布:跑步内衣 推荐 知乎 编辑:程序博客网 时间:2024/06/05 16:31
【题目链接】:http://codeforces.com/contest/768/problem/C
【题意】
给你n个数字;
让你每次把这n个数字排序;
然后对奇数位的数字进行异或操作,然后对新生成的序列再重复上述操作总共k次;
问最后的序列的最小值和最大值分别是多少;
【题解】
可以用计数排序来搞;
因为数字最大为1000;
所以将近O(K*1000)的复杂度;
完全可以的;
每次从小到大(0到1000(枚举数字;
然后根据该数字的个数判断该数字有几个数字要进行异或,几个数字保持原样.
然后在新的计数排序数组里面记录一下就好;
最后一遍循环搞出最大最小值就好;
【完整代码】
#include <bits/stdc++.h>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%lld",&x)typedef pair<int,int> pii;typedef pair<LL,LL> pll;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);const int N = 1e3+500;int n,k,xx;int bo[2][N];int main(){ //freopen("F:\\rush.txt","r",stdin); rei(n),rei(k),rei(xx); rep1(i,1,n) { int y; rei(y); bo[0][y]++; } int now = 0; rep1(i,1,k) { rep1(j,0,1100) bo[1-now][j] = 0; int x = 0; rep1(j,0,1100) if (bo[now][j]>0) { int ju = bo[now][j]&1; if (x==0) { if (ju) { bo[1-now][j^xx]+=((bo[now][j]+1)/2); bo[1-now][j]+=(bo[now][j]-((bo[now][j]+1)/2)); x = 1; } else { bo[1-now][j^xx]+=bo[now][j]/2; bo[1-now][j]+=(bo[now][j]-(bo[now][j]/2)); x = 0; } } else { if (ju) { bo[1-now][j^xx]+=((bo[now][j]-1)/2); bo[1-now][j]+=(bo[now][j]-((bo[now][j]-1)/2)); x = 0; } else { bo[1-now][j^xx]+=((bo[now][j])/2); bo[1-now][j]+=(bo[now][j]-((bo[now][j])/2)); x = 1; } } } now = 1-now; } rep2(i,1100,0) if (bo[now][i]>0) { printf("%d ",i); break; } rep1(i,0,1100) if (bo[now][i]>0) { printf("%d\n",i); break; } return 0;}
0 0
- Codeforces 768C Jon Snow and his Favourite Number 构造
- Codeforces 768C Jon Snow and his Favourite Number
- 【codeforces 768C】Jon Snow and his Favourite Number
- codeforces 768C Jon Snow and his Favourite Number 【思维】
- Codeforces 768C Jon Snow and his Favourite Number【思维】
- CodeForces 768C Jon Snow and his Favourite Number
- Codeforces Round #399:C. Jon Snow and his Favourite Number
- C. Jon Snow and his Favourite Number
- codeforces 768 C Jon Snow and his Favourite Number(循环节)
- CodeForces 768C Jon Snow and his Favourite Number 暴力 空间换时间
- Codeforces768C Jon Snow and his Favourite Number
- Codeforces768C-Jon Snow and his Favourite Number
- Jon Snow and his Favourite Number
- Codeforces Round #399 (Div. 1 + Div. 2, combined)C. Jon Snow and his Favourite Number
- Codeforces 768D Jon and Orbs
- codeforces 768D Jon and Orbs
- Codeforces 768D Jon and Orbs (DP)
- codeforces 768D Jon and Orbs
- zookeeper原理
- MySQL 高可用架构在业务层面细化分析研究
- 阿里云搭建SVN服务器
- 错误: 找不到符号
- iOS
- 【codeforces 768C】Jon Snow and his Favourite Number
- Merge into使用详解2
- Swift & Perfect 初步搭建d
- 离开了公司,你还有什么
- [Coursera 计算导论与C语言基础] 第十周作业(下)
- C++11 auto_ptr shared_ptr unique_ptr
- java主函数main能不能去掉 String[] args?
- Java过滤器,拦截器,监听器对比
- python GUI程序编译报错