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

时间:2023-03-10 00:47:21
Codeforces Round #439 (Div. 2)【A、B、C、E】

Codeforces Round #439 (Div. 2)

codeforces 869 A. The Artful Expedient

看不透(

 #include<cstdio>
int main(){
puts("Karen");
return ;
}

15ms

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

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

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll a, b, x, y;
scanf("%lld %lld", &a, &b);
if(b-a>=) puts("");
else {
ll d = b - a; ll t = ;
x = b % ;
for(int i = ; i < d; ++i) t *= (x-i);
printf("%lld\n", t%);
}
return ;
}

15ms

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

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

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = ;
const int N = ;
ll c[N][N];
void init() {
int i, j;
for(i = ; i < N; ++i) c[][i] = ;
for(i = ; i < N; ++i)
for(j = i; j < N; ++j)
c[i][j]=(c[i-][j]+c[i-][j-]*j)%mod;
}
int main() {
init();
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
if(x>y)swap(x, y); if(x>z)swap(x, z); if(y>z)swap(y,z);
printf("%lld\n", (((c[x][y]*c[x][z])%mod)*c[y][z])%mod );
return ;
}

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),要求行走时不能通过障碍物。

//不会,,先留着。。

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

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

 #include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
inline void read(int&a){char c;while(!(((c=getchar())>='')&&(c<='')));a=c-'';while(((c=getchar())>='')&&(c<=''))(a*=)+=c-'';}
const int N = ;
int mp[N][N];
int fun(int r, int c) {
int top = ;
for(int i = c; i >= ; --i) {
if(mp[r][i] > ) {
if(!top) return mp[r][i];
else top++;
}
else if(mp[r][i] < ) top--;
}
return ;
}
int main() {
int n, m, q, i, j;
int t, r1, c1, r2, c2;
read(n); read(m); read(q);
for(j = ; j <= q; ++j) {
read(t); read(r1); read(c1); read(r2); read(c2);
if(t==) {
for(i = r1; i <= r2; ++i) {
mp[i][c1] = j; mp[i][c2+] = -;
}
}else if(t == ) {
for(i = r1; i <= r2; ++i) {
mp[i][c1] = mp[i][c2+] = ;
}
}else {
if(fun(r1, c1)==fun(r2, c2)) puts("Yes"); else puts("No");
}
}
return ;
}

1887ms