# Atcoder beginer contest 211 a ~ e problem solution

Posted by WebGeek182 on Fri, 14 Jan 2022 19:26:54 +0100

# A - Blood Pressure

• meaning of the title
calculation A − B 3 + B \frac{A-B}{3} + B 3A−B​+B

• Problem solving ideas
be careful A − B 3 \frac{A-B}{3} 3A − B determines whether the result obtained is an integer, that is, whether it can be divided 3 3 3.

• AC code

/**
*@filename:A
*@author: pursuit
*@csdn:unique_pursuit
*@email: 2825841950@qq.com
*@created: 2021-07-24 19:59
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 100000 + 5;
const int P = 1e9+7;

int a,b;
void solve(){
}
int main(){
cin >> a >> b;
if((a - b) % 3){
printf("%.7lf\n",(a - b) * 1.0 / 3 + b);
}
else{
cout << (a - b) / 3 + b << endl;
}
solve();
return 0;
}


# B - Cycle Hit

• meaning of the title
Give a series of strings to judge whether the required string is inside.

• Problem solving ideas
utilize m a p map map or other containers record the string that appears, and finally judge whether the required string is in it.

• AC code

/**
*@filename:B
*@author: pursuit
*@csdn:unique_pursuit
*@email: 2825841950@qq.com
*@created: 2021-07-24 20:03
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 100000 + 5;
const int P = 1e9+7;

string s;
map<string,int> p;
void solve(){
}
int main(){
for(int i = 0; i < 4; ++ i){
cin >> s;
p[s] ++;
}
if(p["H"] && p["2B"] && p["3B"] && p["HR"]){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
solve();
return 0;
}


# C - chokudai

• meaning of the title
Give you a string and calculate how many strings in the string are chokudai.

• Problem solving ideas
For this problem, and the longest common subsequence are of the same type, but here is the number of statistical schemes. Let's define the status first: d p [ i ] [ j ] dp[i][j] dp[i][j] indicates front i i i characters, which have been matched to the second character in chokudai j j Number of schemes with j characters. Let's analyze the initial state first. about j = 0 j = 0 j=0, we know that since there is no need to match, the number of schemes is naturally 1 1 1. about i = 0 , j > 0 i = 0,j >0 I = 0, J > 0. Since there are no characters to match, the number of schemes is 0 0 0 So now, let's analyze the state transition, that is, the current second phase i i Is the i character the same as the second character j j If j characters are equal: s 1 [ i ] = s 2 [ j ] s1[i] = s2[j] s1[i]=s2[j], which shows that we are at this time d p [ i − 1 ] [ j − 1 ] dp[i - 1][j-1] dp[i − 1][j − 1] and d p [ i − 1 ] [ j ] dp[i-1][j] dp[i − 1][j] status can be transferred to d p [ i ] [ j ] dp[i][j] dp[i][j], i.e d p [ i ] [ j ] = d p [ i − 1 ] [ j − 1 ] + d p [ i − 1 ] [ j ] dp[i][j] = dp[i-1][j-1]+dp[i-1][j] dp[i][j]=dp[i−1][j−1]+dp[i−1][j]； If not, then d p [ i − 1 ] [ j − 1 ] dp[i-1][j-1] dp[i − 1][j − 1] cannot be transferred, so d p [ i ] [ j ] = d p [ i − 1 ] [ j dp[i][j]=dp[i-1][j dp[i][j]=dp[i − 1][j. therefore, this problem can be solved.

• AC code

/**
*@filename:C
*@author: pursuit
*@csdn:unique_pursuit
*@email: 2825841950@qq.com
*@created: 2021-07-24 20:06
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 100000 + 5;
const int P = 1e9+7;

int dp[N][10];//dp[i][j] represents the number of combinations of the first I characters that have been paired to the jth character in the matching string.
char s[N];
void solve(){
char temp[10] = " chokudai";
int len1 = strlen(s + 1),len2 = strlen(temp + 1);
for(int j = 1; j <= len2; ++ j){
dp[0][j] = 0;
}
for(int i = 0; i <= len1; ++ i){
dp[i][0] = 1;
}
for(int i = 1; i <= len1; ++ i){
for(int j = 1; j <= len2; ++ j){
if(s[i] == temp[j]){
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % P;
}
else{
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[len1][len2] << endl;
}
int main(){
cin >> s + 1;
solve();
return 0;
}


# D - Number of Shortest paths

• meaning of the title
Here you are n n n vertices m m The undirected graph with m edges now needs you to calculate from 1 1 1 to n n How many shortest paths are there for n.

• Problem solving ideas
Nature is utilization b f s bfs bfs, but here we need to pay attention to whether the diffusion point has encountered the shortest path initialized. If so, and the shortest path from the current point to this point is the same, it means that we have two ways to reach, and the number of schemes of these two ways can be added.

• AC code

/**
*@filename:D
*@author: pursuit
*@csdn:unique_pursuit
*@email: 2825841950@qq.com
*@created: 2021-07-24 20:14
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 200000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1e9+7;

struct node{
int to,next;
}edges[N << 1];
int n,m,u,v;
int cnt[N],dist[N];//dist is the shortest path array. dist[i] represents the shortest path from 1 to I.
void add(int u,int v){
edges[++ tot].to = v;
}
void bfs(){
queue<int> q;
q.push(1);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; i; i = edges[i].next){
int v = edges[i].to;
if(dist[v] == INF){
//Description not initialized.
dist[v] = dist[u] + 1;
cnt[v] = cnt[u];
q.push(v);
}
else if(dist[v] == dist[u] + 1){
//Description has been initialized. And the shortest path is from here.
cnt[v] += cnt[u];
cnt[v] %= P;
}
}
}
}
void solve(){
fill(dist,dist + N,INF);
dist[1] = 0;
cnt[1] = 1;
bfs();
cout << cnt[n] << endl;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++ i){
scanf("%d%d", &u, &v);
}
solve();
return 0;
}


# E - Red Polyomino

• meaning of the title
Here you are n × n n\times n n × N's cell matrix, in which each cell attribute is either white or black. Now you need to calculate how many schemes can draw white blocks into red blocks to make the region connected and the size is k k k.

• Problem solving ideas
It's easy to think of d f s dfs dfs, but we need a lot of pruning operations, that is, when we store the processed map. Pay attention to starting from each white block once. stay d f s dfs In the process of dfs, backtracking must return to the original state.

• AC code

/**
*@filename:E
*@author: pursuit
*@csdn:unique_pursuit
*@email: 2825841950@qq.com
*@created: 2021-07-25 11:17
**/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 100000 + 5;
const int P = 1e9+7;

int n,k,ans;
vector<string> s;
int go[4][2] = {0,1,0,-1,1,0,-1,0};
map<vector<string>,int> p;//duplicate removal.
bool flag;
void dfs(int num){
//From (x,y), there are k to be dyed.
if(p[s]){
return;
}
p[s]++;
if(num == 0){
/* for(int i = 0; i < s.size(); ++ i){
cout << s[i] << endl;
}
cout << endl; */
ans ++;
return;
}
for(int i = 0; i < n; ++ i){
for(int j = 0; j < n; ++ j){
if(s[i][j] == '.'){
for(int c = 0; c < 4; ++ c){
int dx = i + go[c][0],dy = j + go[c][1];
if(dx >= 0 && dx < n && dy >= 0 && dy < n && s[dx][dy] == 'r'){
s[i][j] = 'r';
dfs(num - 1);
s[i][j] = '.';
}
}
}
}
}
}
void solve(){
for(int i = 0; i < n; ++ i){
for(int j = 0; j < n; ++ j){
if(s[i][j] == '.'){
s[i][j] = 'r';
dfs(k - 1);
s[i][j] = '.';
}
}
}
cout << ans << endl;
}
int main(){
cin >> n >> k;
s.resize(n);
for(int i = 0; i < n; ++ i){
cin >> s[i];
}
solve();
return 0;
}