codeforces 869A/B/C
1 second
256 megabytes
standard input
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.
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.
简单的模拟题;
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");
}
1 second
256 megabytes
standard input
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.
The first and only line of input contains two space-separated integers a 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
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;
}
1 second
256 megabytes
standard input
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 a, b 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.
The first and only line of input contains three space-separated integers a, b and c (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, modulo 998 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 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的更多相关文章
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- codeforces 869A The Artful Expedient【暴力枚举/亦或性质】
A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...
- CodeForces - 869A The Artful Expedient
题意:有两个序列X和Y,各含n个数,这2n个数互不相同,若满足xi^yj的结果在序列X内或序列Y内的(xi,yj)对数为偶数,则输出"Karen",否则输出"Koyomi ...
- codeforces 869A
A. The Artful Expedient time limit per test 1 second memory limit per test 256 megabytes input stand ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- Java实现匿名内部类的简单应用
在查看数码相片时,通常会使用一款图片查看软件,该软件应该能遍历文件夹下的所有图片并进行显示.编写程序,实现一个图片查看软件,它可以支持6张图片,通过单击不同的按钮就可以查看不同的图片. 思路分析:就是 ...
- AppStore应用转让流程
可能大家都有这样的情况,给公司客户开发一个ios app的前期阶段是先发布在自己公司的开发者账户上面的,而不是直接发布在客户的开发者账号上面,这个到后期的话就有一个转让的事情,俗称“过户”. 步骤如下 ...
- jackson 转换 enum 类型
REST API 接口要求 requster json 的 lifeCycle 域只能填 YOUNG, OLD,对于其他的 lifeCycle,都要给 requester 返回 bad request ...
- 配置Django框架为生产环境的注意事项(DEBUG=False)
问题描述: Django1.10版本中框架中settings.py配置文件 配置文件settings.py配置了下面两项: DEBUG= False ALLOWED_HOSTS = ['*'] #这样 ...
- yarn基础架构
Yarn的基本架构 Yarn是Hadoop2.0中的资源管理系统,它的基本设计思想是将MRv1中的JobTracker拆分成两个独立的服务:一个全局的资源管理器ResourceManager和每个应用 ...
- Linux应急响应入侵排查思路
0x00 前言 当企业发生黑客入侵.系统崩溃或其它影响业务正常运行的安全事件时,急需第一时间进行处理,使企业的网络信息系统在最短时间内恢复正常工作,进一步查找入侵来源,还原入侵事故过程,同时给出解 ...
- SaltStack 批量分发目录
这里演示如何将 salt-master 上的目录批量分发到多台 salt-minion,步骤如下: [root@localhost ~]$ cat /srv/salt/top.sls # 先定义入口配 ...
- hadoop核心逻辑shuffle代码分析-map端
首先要推荐一下:http://www.alidata.org/archives/1470 阿里的大牛在上面的文章中比较详细的介绍了shuffle过程中mapper和reduce的每个过程,强烈推荐先读 ...
- 《Mysql 入门很简单》(读后感②)
接上篇~ 1.UNIX时间戳函数: UNIX_TIMESTAMP()函数以UNIX时间戳的形式返回当前时间: UNIX_TIMESTAMP(d)函数将时间d以UNIX时间戳的形式返回: FROM_UN ...
- Jdk1.8在CentOS7中的安装与配置
自从2014年3月19日甲骨文公司发布Java 8.0的正式版以来,面向对象的Java语言不仅朝着一个更好的方向发展,而且吸取了当前比较流行的函数式编程的特性——Java 8.0加入了函数式编程的特点 ...