A. The Artful Expedient

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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, ..., xnand 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.

Input

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 = yji ≠ j and xi = xji ≠ j and yi = yj.

Output

Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.

Examples
input
3
1 2 3
4 5 6
output
Karen
input
5
2 4 6 8 10
9 7 5 3 1
output
Karen
Note

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.

简单的模拟题;

AC代码:

 #include<cstdio>
#include<map>
using namespace std;
int n,num[][];
map<int,int> vis;
int main()
{
scanf("%d",&n);
for(int r=;r<;r++) for(int i=;i<=n;i++) {scanf("%d",&num[r][i]);vis[num[r][i]]=;}
int pair=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(vis.count(num[][i]^num[][j])) pair++;
}
}
if(pair%) printf("Koyomi\n");
else printf("Karen\n");
}

B. The Eternal Immortality

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 every a! years. Here a! denotes the factorial of integer a, 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 of b! years, that is, . Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Examples
input
2 4
output
2
input
0 10
output
0
input
107 109
output
2
Note

In the first example, the last digit of  is 2;

In the second example, the last digit of  is 0;

In the third example, the last digit of  is 2.

简单模拟题,稍微做一些特别的处理即可;

AC代码:

 #include<iostream>
using namespace std;
typedef unsigned long long LLU;
LLU n,m;
int main()
{
cin>>n>>m;
int ans=;
for(LLU i=m;i>n;i--)
{
ans*=i%;
ans%=;
if(ans==) break;
}
cout<<ans;
}

C. The Intriguing Obsession

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

— 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 of ab and c 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 length 1. 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 is at least 3, 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 modulo 998 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.

Input

The first and only line of input contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output

Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

Examples
input
1 1 1
output
8
input
1 2 2
output
63
input
1 3 5
output
3264
input
6 2 9
output
813023575
Note

In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 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.

题意:

有三堆群岛,分别用不同颜色标记,现在在岛间建桥,桥长度均为1,限制条件:同颜色的岛间距离不小于3或者没有连接,求有多少种建桥方案(结果对998244353取模)。

题解:

对于两堆岛,假设岛堆1有m个岛,岛堆2有n个岛,且满足m<=n,则不难得到两个两堆岛间建立桥的方案数:

$f(m,n)=\sum_{i=0}^{m}C_{m}^{i}A_{n}^{i}=\sum_{i=0}^{m}C_{m}^{i}C_{n}^{i}i!$

关于如何求组合数C(n,m):http://www.cnblogs.com/xienaoban/p/6798058.html

因为我们看到,a,b,c最大不超过5000,所以可以用迭代的方式求组合数和阶乘;

最后根据公式计算出答案即可;

 #include<cstdio>
#include<algorithm>
#define MAX 5003
#define MOD 998244353
using namespace std;
typedef long long ll;
ll C[MAX][MAX],fac[MAX];
void calc_Cmn()//求组合数
{
for(int i=;i<MAX;i++)
{
C[i][]=C[i][i]=;
for(int j=;j<i;j++) C[i][j]=(C[i-][j-]+C[i-][j])%MOD;
}
}
void calc_factorial()//求阶乘
{
fac[]=fac[]=;
for(int i=;i<MAX;i++) fac[i]=(fac[i-]*i)%MOD;
}
ll f(int m,int n)
{
ll ret=;
for(int i=;i<=m;i++)
{
ret+=(((C[m][i]*C[n][i])%MOD)*fac[i])%MOD;
ret=ret%MOD;
}
return ret;
}
int main()
{
calc_Cmn();
calc_factorial();
int x,y,z,m,n;
scanf("%d%d%d",&x,&y,&z); m=min(x,y), n=max(x,y);
ll ans1=f(m,n);
m=min(x,z), n=max(x,z);
ll ans2=f(m,n);
m=min(y,z), n=max(y,z);
ll ans3=f(m,n); printf("%I64d\n",(((ans1*ans2)%MOD)*ans3)%MOD);
}

PS.里面包含了求组合数和阶乘的算法模板

codeforces 869A/B/C的更多相关文章

  1. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  2. codeforces 869A The Artful Expedient【暴力枚举/亦或性质】

    A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...

  3. CodeForces - 869A The Artful Expedient

    题意:有两个序列X和Y,各含n个数,这2n个数互不相同,若满足xi^yj的结果在序列X内或序列Y内的(xi,yj)对数为偶数,则输出"Karen",否则输出"Koyomi ...

  4. codeforces 869A

    A. The Artful Expedient time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. oracle 定义带参数的视图

    1.定义包 CREATE OR REPLACE package p_view_param is --定义开始日期-- function set_beginTime(beginTime varchar2 ...

  2. BearSkill纯代码搭建iOS界面

    欢迎相同喜欢动效的project师/UI设计师/产品增加我们 iOS动效特攻队–>QQ群:547897182 iOS动效特攻队–>熊熊:648070256 浅谈一下 关于iOS兼容布局一直 ...

  3. SpringBoot------注解把配置文件自动映射到属性和实体类

    1.映射到属性 package top.ytheng.demo.controller; import org.springframework.beans.factory.annotation.Valu ...

  4. 如何把JavaScript数组中指定的一个元素移动到第一位

    目的:通过LocalStrorage实现存储搜索历史--结合store.js实现 代码如下: function addSearchHistory(key,value) { var oldArr = s ...

  5. Struts2_day03讲义_使用Struts2完成对客户查询的优化操作

  6. PHP代码审计笔记--弱类型存在的安全问题

    0x01 前言 PHP 是一门弱类型语言,不必向 PHP 声明该变量的数据类型,PHP 会根据变量的值,自动把变量转换为正确的数据类型. 弱类型比较,是一个比较蛋疼的问题,如左侧为字符串,右侧为一个整 ...

  7. iOS开发-VFL初窥

    VFL是苹果为了简化Autolayout的编码而推出的抽象语言,在上一篇博客中我们发现如果使用NSLayoutConstraint来添加约束是非常繁琐的. 一个简单的Frame需要添加四个NSLayo ...

  8. N76E003之IO控制

    N76E003最多支持26个可位寻址的通用I/O引脚,分成4组 P0 到 P3 .每一个端口有它的端口控制寄存器(Px).端口控制寄存器的写和读有不同的意思.写端口控制寄存器设置输出锁存逻辑值,读端口 ...

  9. Lua中的注释

    Lua中有两种注释:行注释和块注释.行注释以“--”开头,可以注释这一行后面的内容.块注释以“--[[”开始,以“--]]”结尾,可以注释这个范围内的整个内容:块注释可以注释多行内容.下面是一个示例: ...

  10. iOS - UIScrollView 相关属性代理详解

    一.UIScrollView的属性和代理方法详解 属性: - (void)viewDidLoad { [super viewDidLoad]; _scrollView.backgroundColor ...