ABC211

AtCoder Beginner Contest 211

A - Blood Pressure

水题,按题目给的式子输出即可

1
2
3
4
5
6
7
8
9
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    double c = ((double)a - b) / 3 + b;
    printf("%lf\n", c);
    return 0;
}

B - Cycle Hit

暴力判断

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
using namespace std;
bool st[4];
int main() {
    string s[4];
    for (int i = 0; i < 4; i++)
        cin >> s[i];

    for (int i = 0; i < 4; i++) {
        if (s[i] == "H")  st[0] = true;
        if (s[i] == "2B") st[1] = true;
        if (s[i] == "3B") st[2] = true;
        if (s[i] == "HR") st[3] = true;
    }
    bool flag = true;
    for (int i = 0; i < 4; i++) 
        if (!st[i])
            flag = false;

    if (flag)
        cout << "Yes" << endl;
    else
        cout << " No" << endl;
    return 0;
}

C - chokudai

简单 $dp$,$dp[i][j]$ 代表到 $i$ 位置前缀长度为 $j$ 的个数。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 7, mod = 1e9 + 7;
ll dp[M][8];
char s[M];
// c, h, o, k, u, d, a, i
string cmp = " chokudai";

int main() {
    cin >> s + 1;
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) {
        dp[i - 1][0] = 1;
        for (int j = 1; j < 9; j++) {
            if (s[i] == cmp[j]) {
                dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
            } else
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[len][8] << endl;
    return 0;
}

D - Number of Shortest paths

由于边长的权值为 $1$ ,所以可以通过 $bfs$ 来求解最短路的条数。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 7, mod = 1e9 + 7;

struct Node {
    int to, nxt;
} tr[M * 2];

int idx, head[M];
int cnt[M];
ll num[M];
bool st[M];
void add(int u, int v) {
    tr[idx] = {v, head[u]};
    head[u] = idx++;
}

void bfs() {
    queue<int> q;
    q.push(1);
    num[1] = 1;
    st[1] = true;
    while (q.size()) {
        int now = q.front();
        q.pop();
        for (int i = head[now]; ~i; i = tr[i].nxt) {
            int j = tr[i].to;
            if (st[j] && cnt[j] == cnt[now] + 1) {
                num[j] = (num[j] + num[now]) % mod;
            } else if (!st[j]) {
                cnt[j] = cnt[now] + 1;
                num[j] = num[now];
                st[j] = true;
                q.push(j);
            }
        }
    }
}

int main() {
    memset(head, -1, sizeof head);
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        add(x, y), add(y, x);
    }
    bfs();
    printf("%lld\n", num[n]);
    return 0;
}
Licensed under CC BY-NC-SA 4.0