A. The Artful Expedient

题目链接:http://codeforces.com/contest/869/problem/A

题目意思:给你两个数列,各包含n个数,现在让你从上下两个数列中各取一个数a[i],b[j],如果a[i]^b[j]在这2×n个数里面出现过,那么就获得一分,问将任意的a[i],b[j]之间的亦或之后,如果分数是奇数则Koyomi胜利,否则Karen胜利。问最后到底谁胜了。

题目思路:非常无聊的题目,暴力都可以过,就是暴力枚举a[i],b[j],把所有答案都算出来,然后再用一个判定存在的数组,来判定是否出现过,然后算出最后的分数,但是有一个坑点.a[i]^a[j]可能会爆2*10^6所以当答案超出这个值的时候可以直接continue,或者你开4*10^6也是没有问题的,比赛的时候我是这么做的,但是实际上并不需要这么做,因为假设存在a[i]^b[j]==x存在于这2*n个数之中,那么x^a[i]=b[j](x与b[j]一组)或者x^b[j]=a[i](x与a[i]一组),所以存在一组就不定存在另一组与之对应,所以必定存在偶数组,所以karen必胜。

贴出我暴力的代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月06日 星期五 21时34分51秒
File Name :A.cpp
************************************************ */
#include <bits/stdc++.h>
typedef long long LL;
#define endl "\n"
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
bool q[*+]={false};
long long a[];
long long b[];
int main(){
ios::sync_with_stdio(false);cin.tie();
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a[i];
q[a[i]]=true;
}
for(int i=;i<n;i++){
cin>>b[i];
q[b[i]]=true;
}
int ans=;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
int tmp=a[i]^b[j];
if(tmp>*1000000LL) continue;
if(q[tmp]) ans++;
}
}
if(ans&) cout<<"Koyomi"<<endl;
else cout<<"Karen"<<endl;
return ;
}

B. The Eternal Immortality

题目链接:http://codeforces.com/contest/869/problem/B

题目意思:给出两个数a,b其中a<=b,求b!/a!的最后一位是多少?

题目思路:暴力题,首先答案就是(a+1)*(a+2)*(a+3)*(a+4)…………*b,一种思路是暴力直接算,当末尾的的数变成0了以后直接就输出0结束,如果还没有变成0,就循环到b了,直接输出答案,另一种也是暴力算,但是记录一个是否已经含有2和5的这两个质因子(因为一个数包含2和5两个质因子,末尾必定是0)。

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月06日 星期五 21时53分14秒
File Name :B.cpp
************************************************ */
#include <bits/stdc++.h>
typedef long long LL;
#define endl "\n"
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=1e9+;
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie();
long long a,b;
long long sum=;
int c2=,c5=;
cin>>a>>b;
for(long long i=a+;i<=b;i++){
sum*=i%;
sum%=;
if(i%2LL==) c2++;
if(i%5LL==) c5++;
if(c2&&c5) break;
}
if(c2&&c5) cout<<<<endl;
else cout<<sum<<endl;
return ;
}

C. The Intriguing Obsession

题目链接:http://codeforces.com/contest/869/problem/C

题目意思:现在给出红色,蓝色,紫色的点若干,然后现在要在他们之间建桥,相同颜色的点之间不能存在通路,就算存在通路,最小的距离也要大于等于3,问有多少种建桥的方案,答案数mod998244353。

题目思路:相同颜色的点之间不能存在通路,而且最短距离不能小于3,那么我们先考虑其中两种颜色,比如红色和蓝色,那么如果一个红色和两个蓝色之间存在连线,那么就不满足题目的条件,所以我们可以把题目转换为x个不同的小球装入y个不同的箱子,每个箱子最多放一个小球,可以选择不把小球放进箱子,所以公式就是Σ(k=0,min(x,y))C(x,k)*(y!/(y-k)!)或者Σ(k=0,min(x,y))C(y,k)*(x!/(x-k)!)也是可以的,答案是一样的,我们设其为F(x,y),那么最后答案是就是如果三个小球的数量是x,y,z了话,那么最后答案就是F(x,y)*F(x,z)*F(y,z)。

代码:

 /* ***********************************************
Author :xiaowuga
Created Time :2017年10月07日 星期六 13时10分37秒
File Name :C.cpp
************************************************ */
#include <bits/stdc++.h>
typedef long long LL;
#define endl "\n"
#define inf 0x3f3f3f3f
const long long N=;
const long long mod=;
using namespace std;
vector<LL>fac,finv;
void init_fav_finv(int n){
fac.resize(n);
finv.resize(n);
fac[]=;
for(int i=;i<n;i++) fac[i]=fac[i-]*i%mod;
finv[]=;
for(int i=;i<n;i++) finv[i]=finv[mod%i]*(mod-mod/i)%mod;
finv[]=;
for(int i=;i<n;i++) finv[i]=finv[i-]*finv[i]%mod;
}
LL Comb(LL n,LL m){
return fac[n]*finv[m]%mod*finv[n-m]%mod;
}
LL Perm(LL n,LL m){
return fac[n]*finv[m]%mod;
}
LL cal(LL x,LL y){
if(x<y) swap(x,y);
LL sum=;
for(LL i=;i<=y;i++){
LL tmp=Comb(y,i)*Perm(x,x-i)%mod;
sum=(sum+tmp)%mod;
}
return sum;
}
int main(){
ios::sync_with_stdio(false);cin.tie();
init_fav_finv();
LL a,b,c;
cin>>a>>b>>c;
cout<<cal(a,b)*cal(a,c)%mod*cal(b,c)%mod<<endl;
return ;
}
05-11 20:14