Codeforces 869A The Artful Expedient
来源:互联网 发布:mac快速认证 编辑:程序博客网 时间:2024/06/05 15:01
Rock... Paper!
After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.
A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xn and y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.
Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xormeans the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.
Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.
The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.
The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.
The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.
Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yj; i ≠ j and xi = xj; i ≠ j and yi = yj.
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
31 2 34 5 6
Karen
52 4 6 8 109 7 5 3 1
Karen
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again.
附题目链接:http://codeforces.com/problemset/problem/869/A
先贴上暴力代码: 用vis[]标记异或后的值得时候要注意异或后的范围可能会超出2e6;
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e7 + 10;int vis[maxn];int n,a[2010],b[2010];int main(){ while(~scanf("%d",&n)){ for(int i = 1; i <= n; i ++) scanf("%d",&a[i]); for(int i = 1; i <= n; i ++) scanf("%d",&b[i]); memset(vis,0,sizeof(vis)); for(int i = 1; i <= n; i ++){ vis[a[i]] ++; vis[b[i]] ++; } int cnt = 0; for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ if(vis[a[i]^b[j]]) cnt ++; } } if(cnt % 2) printf("Koyomi\n"); else printf("Karen\n"); } return 0;}
再说下另一种思路:对于任意一个xi ^yj = z ,假设z属于X,令z = xk,即 xi ^ yj = xk, 由异或的原理可得: xk ^ yj = xi。 假设z属于Y,令z=yk,即xi ^ yj = yk => xi ^ yk = yj;
所以只要xi ^yj的结果在X和Y之间,则一定会有偶数个异或对产生。
#include <cstdio>using namespace std;int main(){ printf("Karen\n"); return 0;}
- codeforces 869A The Artful Expedient
- Codeforces 869A. The Artful Expedient
- Codeforces 869A The Artful Expedient
- CodeForces 869A The Artful Expedient
- codeforces—— 869A —— The Artful Expedient
- A. The Artful Expedient
- A. The Artful Expedient
- Codeforces Round #439 (Div. 2) A. The Artful Expedient
- Codeforces Round #439 (Div. 2) A. The Artful Expedient
- Codeforces Round #439 (Div. 2) A. The Artful Expedient
- CF 869 A. The Artful Expedient【异或】
- CF 869 A. The Artful Expedient(异或)
- Codeforces869A The Artful Expedient
- 【codeforces869A】The Artful Expedient
- Codeforces Round #439 A The Artful Expedient 博弈解释 +暴力写法
- Codeforces Round #439 (Div. 2) The Artful Expedient
- codeforces The Artful Expedient(数学思维题)
- Codeforces Round #439 (Div. 2) The Artful Expedient
- php通过JODConverter将word转换为pdf
- C++引用segment fault
- css基础
- 八大排序算法的python实现
- servlet的init()方法抛出空指针异常
- Codeforces 869A The Artful Expedient
- UE4之跟随移动
- application/json 四种常见的 POST 提交数据方式
- B. Maxim Buys an Apartment
- 制作mongodb的Docker镜像文件
- ROS多线程订阅
- c语言历史
- UVA
- VS2008 发生的一些错误1