Jon Snow and his Favourite Number
来源:互联网 发布:剑灵金燕捏脸数据 编辑:程序博客网 时间:2024/05/29 12:35
C. Jon Snow and his Favourite Number
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times:
- Arrange all the rangers in a straight line in the order of increasing strengths.
- Take the bitwise XOR (is written as ) of the strength of each alternate ranger with x and update it's strength.
- The strength of first ranger is updated to , i.e. 7.
- The strength of second ranger remains the same, i.e. 7.
- The strength of third ranger is updated to , i.e. 11.
- The strength of fourth ranger remains the same, i.e. 11.
- The strength of fifth ranger is updated to , i.e. 13.
Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him?
First line consists of three integers n, k, x (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) — number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively.
Second line consists of n integers representing the strengths of the rangers a1, a2, ..., an (0 ≤ ai ≤ 103).
Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.
5 1 29 7 11 15 5
13 7
2 100000 569605 986
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>#include<vector>#include<algorithm>int maxi[100005];int mini[100005];using namespace std;vector <int> a;int main(){ int m,k,n,data; scanf("%d%d%d",&m,&k,&n); for (int i=0;i<m;i++) { scanf("%d",&data); a.push_back(data); } sort(a.begin(),a.end()); maxi[0]=a[m-1]; // mini[0]=a[0]; for(int i=1;i<=k;i++) { sort(a.begin(),a.end()); maxi[i]=a[m-1]; mini[i]=a[0]; if (i>=3) { if(maxi[i]==maxi[i-1]&&mini[i]==mini[i-1] &&maxi[i]==maxi[i-2]&&mini[i]==mini[i-2] &&maxi[i]==maxi[i-3]&&mini[i]==mini[i-3]) { cout<<a[m-1]<<" "<<a[0]<<endl; return 0; } } for(int j=0;j<a.size();j+=2) { a[j]^=n; } } sort(a.begin(),a.end()); cout<<a[m-1]<<" "<<a[0]<<endl;}
- C. 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 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
- 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 768 C Jon Snow and his Favourite Number(循环节)
- Codeforces Round #399 (Div. 1 + Div. 2, combined)C. Jon Snow and his Favourite Number
- CodeForces 768C Jon Snow and his Favourite Number 暴力 空间换时间
- Jon and Orbs CodeForces
- CodeChef CHSEQ22 Chef and Favourite Sequence
- his first- and
- Jobs And His Apple
- Python 语法
- 禁用Cookie后Session追踪
- 哈弗曼树
- 2-3-4树和B树
- Python 语法练习 -- 乘法表
- Jon Snow and his Favourite Number
- 学习笔记3--给窗口添加一个小坐标
- HDU 2033 JAVA
- leetcode274~H-Index
- 超大背包问题 折半枚举
- 我大C的博客开张啦!!!
- HDU 2034 JAVA
- mysql 触发器的详细用法
- mysql查询当天所有数据以及常用日期函数总结