Codeforces Round #439 (Div. 2)

A. The Artful Expedient

题目连接:http://codeforces.com/contest/869/problem/Aios

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

题目思路:很是无聊的题目,暴力均可以过,就是暴力枚举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必胜。数组

贴出我暴力的代码:session

 1 /* ***********************************************
 2 Author        :xiaowuga
 3 Created Time  :2017年10月06日 星期五 21时34分51秒
 4 File Name     :A.cpp
 5 ************************************************ */
 6 #include <bits/stdc++.h>
 7 typedef long long LL; 
 8 #define endl "\n" 
 9 #define inf 0x3f3f3f3f 
10 const long long N=1000000;
11 const long long mod=1e9+7;
12 using namespace std;
13 bool q[2*1000000+10]={false};
14 long long a[2000];
15 long long b[2000];
16 int main(){
17     ios::sync_with_stdio(false);cin.tie(0);
18     int n;
19     cin>>n;
20     for(int i=0;i<n;i++){
21         cin>>a[i];
22         q[a[i]]=true;
23     }
24     for(int i=0;i<n;i++){
25         cin>>b[i];
26         q[b[i]]=true;
27     }
28     int ans=0;
29     for(int i=0;i<n;i++){
30         for(int j=0;j<n;j++){
31             int tmp=a[i]^b[j];
32             if(tmp>2*1000000LL) continue;
33             if(q[tmp]) ans++;
34         }    
35     }
36     if(ans&1) cout<<"Koyomi"<<endl;
37     else cout<<"Karen"<<endl;
38     return 0;
39 }
View Code

B. The Eternal Immortality

题目连接:http://codeforces.com/contest/869/problem/Bide

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

题目思路:暴力题,首先答案就是(a+1)*(a+2)*(a+3)*(a+4)…………*b,一种思路是暴力直接算,当末尾的的数变成0了之后直接就输出0结束,若是尚未变成0,就循环到b了,直接输出答案,另外一种也是暴力算,可是记录一个是否已经含有2和5的这两个质因子(由于一个数包含2和5两个质因子,末尾一定是0)。spa

代码:3d

 1 /* ***********************************************
 2 Author        :xiaowuga
 3 Created Time  :2017年10月06日 星期五 21时53分14秒
 4 File Name     :B.cpp
 5 ************************************************ */
 6 #include <bits/stdc++.h>
 7 typedef long long LL; 
 8 #define endl "\n" 
 9 #define inf 0x3f3f3f3f 
10 const long long N=1000000;
11 const long long mod=1e9+7;
12 using namespace std;
13 int main(){
14     ios::sync_with_stdio(false);cin.tie(0);
15     long long a,b;
16     long long sum=1;
17     int c2=0,c5=0;
18     cin>>a>>b;
19     for(long long i=a+1;i<=b;i++){
20         sum*=i%10;
21         sum%=10;
22         if(i%2LL==0) c2++;
23         if(i%5LL==0) c5++;
24         if(c2&&c5) break;
25     }
26     if(c2&&c5) cout<<0<<endl;
27     else cout<<sum<<endl;
28     return 0;
29 }
View Code

C. The Intriguing Obsession

题目连接:http://codeforces.com/contest/869/problem/Ccode

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

题目思路:相同颜色的点之间不能存在通路,并且最短距离不能小于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)。

代码:

 1 /* ***********************************************
 2 Author        :xiaowuga
 3 Created Time  :2017年10月07日 星期六 13时10分37秒
 4 File Name     :C.cpp
 5 ************************************************ */
 6 #include <bits/stdc++.h>
 7 typedef long long LL; 
 8 #define endl "\n" 
 9 #define inf 0x3f3f3f3f 
10 const long long N=1000000;
11 const long long mod=998244353;
12 using namespace std;
13 vector<LL>fac,finv;
14 void init_fav_finv(int n){
15     fac.resize(n); 
16     finv.resize(n);
17     fac[0]=1;
18     for(int i=1;i<n;i++) fac[i]=fac[i-1]*i%mod;
19     finv[1]=1;
20     for(int i=2;i<n;i++) finv[i]=finv[mod%i]*(mod-mod/i)%mod;
21     finv[0]=1;
22     for(int i=1;i<n;i++) finv[i]=finv[i-1]*finv[i]%mod;
23 }
24 LL Comb(LL n,LL m){
25     return fac[n]*finv[m]%mod*finv[n-m]%mod;
26 }
27 LL Perm(LL n,LL m){
28     return fac[n]*finv[m]%mod;
29 }
30 LL cal(LL x,LL y){
31     if(x<y) swap(x,y);
32     LL sum=0;
33     for(LL i=0;i<=y;i++){
34         LL tmp=Comb(y,i)*Perm(x,x-i)%mod;
35         sum=(sum+tmp)%mod;
36     }
37     return sum;
38 }
39 int main(){
40     ios::sync_with_stdio(false);cin.tie(0);
41     init_fav_finv(6000);        
42     LL a,b,c;
43     cin>>a>>b>>c;
44     cout<<cal(a,b)*cal(a,c)%mod*cal(b,c)%mod<<endl;
45     return 0;
46 }
View Code
相关文章
相关标签/搜索