Codeforces Round #439
来源:互联网 发布:网络信息工作领导小组 编辑:程序博客网 时间:2024/06/05 06:04
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 choosen distinct positive integers, denoted byx1, x2, ..., xn andy1, y2, ..., yn respectively. They reveal their sequences, and repeat untilall of2n 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 valuexixoryj equals to one of the2n integers. Herexor 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 integern (1 ≤ n ≤ 2 000) — the length of both sequences.
The second line contains n space-separated integersx1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.
The third line contains n space-separated integersy1, 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 andxi = xj;i ≠ j andyi = 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 since6 is an even number.
In the second example, there are 16 such pairs, and Karen wins again.
题目大意:给出两个长度为 n 的数组 a、b,从 a、b 中各选一个元素 ai,bj,问使得 ai xor bj 的结果属于 a、b 中的 2n 个数的 ( i , j ) 的对数。
直接暴力。。。数据范围不大,用数组哈希就行,一开始用的 map 结果T了。。。
代码:
#include<cstdio>#include<algorithm>#include<map>#include<cstring>using namespace std;map<int,bool> m;const int maxn1 = 2e3 + 5;const int maxn2 = 3 * 1e6 + 5;int a[maxn1],b[maxn1];bool c[maxn2];int main(){ memset(c,false,sizeof(c)); int n; scanf("%d",&n); for(int i = 0;i < n; ++i) scanf("%d",&a[i]),c[a[i]] = true; for(int i = 0;i < n; ++i) scanf("%d",&b[i]),c[b[i]] = true; int ans = 0; for(int i = 0;i < n; ++i) { for(int j = 0;j < n; ++j) { if(c[a[i] ^ b[j]]) ++ans; } } printf("%s\n",ans & 1 ? "Koyomi" : "Karen"); return 0;}
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once everya! years. Here a! denotes the factorial of integera, that is,a! = 1 × 2 × ... × a. Specifically,0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan ofb! years, that is, . Note that whenb ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to knowthe last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
The first and only line of input contains two space-separated integersa and b (0 ≤ a ≤ b ≤ 1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
2 4
2
0 10
0
107 109
2
In the first example, the last digit of is2;
In the second example, the last digit of is0;
In the third example, the last digit of is2.
#include<cstdio>#define ll long longusing namespace std;int main(){ ll a,b,c,temp = 1; scanf("%I64d %I64d",&a,&b); for(ll i = b,j = 0;j < 10 && i > a; --i,++j) { c = i % 10; temp = temp * c % 10; } printf("%I64d\n",temp); return 0;}
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist ofa,b andc distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them isat least3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
The first and only line of input contains three space-separated integersa, b andc (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.
Output one line containing an integer — the number of different ways to build bridges, modulo998 244 353.
1 1 1
8
1 2 2
63
1 3 5
3264
6 2 9
813023575
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
#include<cstdio>#include<cstring>#include<algorithm>#define ll long longusing namespace std;const ll mod = 998244353;ll a[3];ll Fastpow(ll a,ll b){ ll ans = 1; while(b > 0) { if(b & 1) ans = (ans * a) % mod; b >>= 1; a = (a * a) % mod; } return ans;}ll Getc(ll a,ll b){ if(a < b) return 0; if(b > a - b) b = a - b; ll s1 = 1,s2 = 1; for(ll i = 0;i < b; ++i) { s1 = s1 * (a - i) % mod; s2 = s2 * (i + 1) % mod; } return s1 * Fastpow(s2,mod - 2) % mod;}ll Lucas(ll n,ll k){ if(k == 0) return 1; return Getc(n % mod,k % mod) * Lucas(n / mod,k / mod) % mod;}ll cal(ll y,ll x){ ll ans = 0,t1 = 1,t2 = 1; for(ll i = x,j = 1;i > x - y; --i,++j) { t2 = t2 * i % mod; t1 = t2 * Lucas(y,j); ans = (ans + t1) % mod; } return ans + 1;}int main(){ for(int i = 0;i < 3; ++i) scanf("%I64d",&a[i]); sort(a,a + 3); ll ans = 1; ans = (ans * cal(a[0],a[1])) % mod; ans = (ans * cal(a[0],a[2])) % mod; ans = (ans * cal(a[1],a[2])) % mod; printf("%I64d\n",ans); return 0;}
- Codeforces Round #439 A
- Codeforces Round #439 B
- Codeforces Round #439
- Codeforces Round #439 B
- Codeforces Round #439
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div.2)
- Codeforces Round #439 (Div.2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- 【codeforces】Codeforces Round #363
- Codeforces Round #439 (Div. 2) C
- Codeforces Round #439 (Div. 2) 题解
- Codeforces Round #439 (Div. 2) 总结
- Codeforces Round #439 (Div. 2)A,B
- Codeforces Round #439 (Div. 2)E详解
- PDF转换图片,图片的切割,图片转换PDF以及PDF加水印等记录贴
- jquery和ajax的关系详细介绍
- linux系统磁盘分区之parted
- 二叉树的应用-----前序中序 推 后序
- 物理存储介质、物理卷、逻辑卷、卷组、快照卷之间的联系
- Codeforces Round #439
- HTML(一) 基本概念
- Java IO 讲解
- linux系统下ps命令
- linux 前后台命令与&用法
- Codeforces Round #439 (Div. 2)
- 一文读懂微生物组
- Codeforces Round #439 (Div. 2) 题解
- 解决mfc编辑框内容写入TXT文件时,自动给每个字符后加入空格问题