Codeforces Round #439 (Div. 2)【A、B、C、E】

Codeforces Round #439 (Div. 2)

codeforces 869 A. The Artful Expedient

看不透(

1 #include<cstdio>
2 int main(){
3     puts("Karen");
4     return 0;
5 }
15ms

codeforces 869B. The Eternal Immortality(数学,水)

题意:输出两个数的阶乘的商的 个位数

题解:两数之差大于5,个位数就是0。小于5直接个位相乘即可。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 typedef long long ll;
 6 int main(){
 7     ll a, b, x, y;
 8     scanf("%lld %lld", &a, &b);
 9     if(b-a>=5) puts("0");
10     else {
11         ll d = b - a; ll t = 1;
12         x = b % 10;
13         for(int i = 0 ; i < d; ++i) t *= (x-i);
14         printf("%lld
", t%10);
15     }
16     return 0;
17 }
15ms

codeforces 869 C. The Intriguing Obsession(组合数)

题意:给出三种颜色岛屿的数量,问有多少种建桥方法。限制是:对于相同颜色的岛屿,要么不联通,要么最少相距为3。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 typedef long long ll;
 6 const ll mod = 998244353;
 7 const int N = 5001;
 8 ll c[N][N];
 9 void init() {
10     int i, j;
11     for(i = 0; i < N; ++i) c[0][i] = 1;
12     for(i = 1; i < N; ++i)
13         for(j = i; j < N; ++j)
14             c[i][j]=(c[i-1][j]+c[i-1][j-1]*j)%mod;
15 }
16 int main() {
17     init();
18     int x, y, z;
19     scanf("%d%d%d", &x, &y, &z);
20     if(x>y)swap(x, y); if(x>z)swap(x, z); if(y>z)swap(y,z);
21     printf("%lld
", (((c[x][y]*c[x][z])%mod)*c[y][z])%mod );
22     return 0;
23 }
140ms

codeforces 869 E. The Untended Antiquity(暴力差分)

题意:给一个n行m列的方格矩形,每格是1*1的单元,有q个操作:t, r1, c1, r2, c2其中t=1表示 以(r1,c1)和(r2,c2)为矩形对角线端点选择相应的矩形平面,在其 边界 放障碍物;t=2同理移除该矩形 边界的障碍物;t=3表示 求(r1,c1)能否到达(r2,c2),要求行走时不能通过障碍物。

//不会,,先留着。。

 题解:看别人做的这题暴力居然能卡过去,神奇,学习了。

给矩形边界移除和放障碍物时依次给每一行的矩形列首尾打标记,查询时,根据点所在的那行信息,判断两点是否在同一区域,即可判断两点是否互相可达。

 1 #include<algorithm>
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
 6 const int N = 2501;
 7 int mp[N][N];
 8 int fun(int r, int c) {
 9     int top = 0;
10     for(int i = c; i >= 1; --i) {
11         if(mp[r][i] > 0) {
12             if(!top) return mp[r][i];
13             else top++;
14         }
15         else if(mp[r][i] < 0) top--;
16     }
17     return 0;
18 }
19 int main() {
20     int n, m, q, i, j;
21     int t, r1, c1, r2, c2;
22     read(n); read(m); read(q);
23     for(j = 1; j <= q; ++j) {
24         read(t); read(r1); read(c1); read(r2); read(c2);
25         if(t==1) {
26             for(i = r1; i <= r2; ++i) {
27                 mp[i][c1] = j; mp[i][c2+1] = -1;
28             }
29         }else if(t == 2) {
30             for(i = r1; i <= r2; ++i) {
31                 mp[i][c1] = mp[i][c2+1] = 0;
32             }
33         }else {
34             if(fun(r1, c1)==fun(r2, c2)) puts("Yes"); else puts("No");
35         }
36     }
37     return 0;
38  }
1887ms
原文地址:https://www.cnblogs.com/GraceSkyer/p/7633702.html