位运算符
1 . and 运算符 &
and 运算符常用于二进制的 取位操作 ,例如一个数 and 1 的结果就是取二进制的最末位,这可以用来判断一个整数的奇偶,二进制的最末尾为 0 表示该数为偶数 , 最末尾为 1 表示该数为奇数。
相同位两个数都为 1 ,则为1, 若有一个不为 1 , 则为 0 。
2 . or 运算符 |
or 运算符通常用于二进制特定位上的无条件赋值,例如一个数 or 1 的结果就是把二进制的最末尾强行变 1 。
3. xor运算 ^
异或的符号是 ^ , 并且两次异或同一个数最后结果不变 , 异或时相同位不同则为 1 , 相同则为 0 。
4 . <<
a << b , 是指把 a 转变为 二进制后左移 b 位 , 每左移一位 , 就相当于乘以 2 。
并且通常认为 a << 1 比 a *2 快 , 因为前者是在更底层一些的操作。
5 . >>
a >> b ,是指将 a 转变为 二进制后右移 b 位 ,每右移一位 , 相当于 除以 2 。
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 xor means 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.
3
1 2 3
4 5 6
Karen
5
2 4 6 8 10
9 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.
思路 : 暴力枚举首先是没问题的 , 但也可以借助位运算的 小技巧 。
若 a ^ b = c ;
则 a ^ c = a ^ b ^ a = b ;
显然若一个数异或出的数在所有数中 , 那么当下一次 在与异或出的数异或就会异或回去 ,因此不管怎么最终一定有偶数个。
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespace std; const int maxn = 4000006; int main() { puts("Karen"); return 0; }