The 2021 Zhejiang University City College Freshman Programming Contest

2022/1/27 6:07:41

本文主要是介绍The 2021 Zhejiang University City College Freshman Programming Contest,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

A

#include <bits/stdc++.h>
using namespace std;
int main() {
    puts("All in!");
    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;
int T, n, m, k;
int main() {
    scanf("%d", &T);
    while (T -- ) {
        scanf("%d%d%d", &n, &m, &k);
        double h = k * 1.0 / m;
        printf("%.10lf\n", h * (n - 1) * 1.0);
    }
    return 0;
}

C
打表找规律

//打表
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
int st[N];
int main() {
    scanf("%d", &n);
    function<void(int, int)> dfs = [&](int d, int sum) {
        if (sum > n) return;
        if (d == n) {
            if (sum != n)   return;
            vector<int> cnt(20); 
            for (int i = 0; i < n; i ++ )
                cnt[st[i]] ++;
            bool flag = 1;
            for (int i = 0; i < n; i ++ ) {
                if (cnt[i] != st[i]) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                for (int i = 0; i < n; i ++ )
                    printf("%d ", st[i]);
                puts("");
            }
            return;
        }
        for (int i = 0; i < n; i ++ ) {
            st[d] = i;
            dfs(d + 1, sum + i);
        }
    };
    dfs(0, 0);
    return 0;
}
//提交代码
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    scanf("%d", &n);
    if (n < 4 || n == 6)    puts("-1");
    else if (n == 4)    puts("1 2 1 0");
    else if (n == 5)    puts("2 1 2 0 0");
    else {
        printf("%d 2 1 ", n - 4);
        for (int i = 1; i <= n - 7; i ++ )
            cout << 0 << " ";
        cout << 1;
        cout << " 0 0 0" << endl;
    }
    return 0;
}

D

#include <bits/stdc++.h>
using namespace std;
int T, n, m, ans;
char s[110];
int main() {
    scanf("%d", &T);
    while (T -- ) {
        ans = 0;
        scanf("%d", &n);
        scanf("%s", s + 1);
        for (int i = 1; i <= n; ) {
            if (s[i] != 'y') {
                i ++;
                continue;
            } 
            int j = i + 1;
            while (j  <= n && s[j] == 'b')  j ++;
            if (j - i >= 3) ans += j - i - 2;
            i = j;
        }
        printf("%d\n", ans);
    }
    return 0;
}

F
BFS

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int T, n, m;
int d[N][N];
bool st[N][N];
char s[N], g[N][N];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct node {
    int x, y;
    int step;
};
int main() {
    scanf("%d", &T);
    while (T -- ) {
        memset(st, 0, sizeof st);
        memset(d, 0x3f, sizeof d);
        scanf("%d%d", &n, &m);
        int x, y;
        for (int i = 1; i <= n; i ++ ) {
            scanf("%s", s + 1);
            for (int j = 1; j <= m; j ++ ) {
                g[i][j] = s[j];
                if (g[i][j] == 'H')
                    x = i, y = j;
            }
        }
        function<void()> bfs = [&]() {
            queue<node> q;
            q.push({x, y, 0});
            d[x][y] = 0;
            st[x][y] = true;
            while (q.size()) {
                auto t = q.front();
                q.pop();
                for (int i = 0; i < 4; i ++ ) {
                    int tx = t.x + dx[i];
                    int ty = t.y + dy[i];
                    if (tx < 1 || tx > n || ty < 1 || ty > m || st[tx][ty]|| g[tx][ty] == '#') continue;
                    d[tx][ty] = t.step + 1;
                    st[tx][ty] = 1;
                    q.push({tx, ty, t.step + 1});
                }
            }
        };
        bfs();
        int time, ans;
        bool flag = 0;
        scanf("%d", &time);
        for (int t = 0; t < time; t ++ ) {
            int a, b;
            scanf("%d%d", &a, &b);
            if (g[a][b] == '#') continue;
            if (d[a][b] <= t && !flag) {
                ans = t;
                flag = 1;
            }
        }
        if (flag)   printf("YES %d\n", ans);
        else puts("NO");
    }
    return 0;
}

G

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 10;
int T, n;
int a[N];
signed main() {
    scanf("%lld", &T);
    while (T -- ) {
        for (int i = 0; i < 7; i ++ )
            scanf("%lld", &a[i]);
        bool flag = 1;
        for (int i = 1; i < 7; i ++ )
            if (a[i] > a[i - 1])
                flag = 0;
        if (flag == 0)  {printf("-1\n"); continue;}
        int cnt = 0;
        for (int i = 6; i >= 0; i -- ) {
            if (a[i] == 0)  continue;
            if (i != 6) cnt += a[i];
            else cnt ++;
            for (int j = 0; j <= i; j ++ )
                a[j] -= a[i];
            if (i == 6) 
                for (int j = 0; j <= i; j ++)
                    if (a[j])   
                        a[j] --;  
            if (a[0] == 0)  break;
        }
        printf("%lld\n", cnt);
    }
    return 0;
}

H

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 998244353;
int T, n;
int qmi(int m, int k, int p)
{
    int res = 1 % p, t = m;
    while (k) {
        if (k & 1) res = res * t % p;
        t = t * t % p;
        k >>= 1;
    }
    return res;
}
signed main() {
    scanf("%lld", &T);
    while (T -- ) {
        scanf("%lld", &n);
        printf("%d\n", qmi(2, n, MOD) - 1);
    }
    return 0;
}

J
模拟

#include <bits/stdc++.h>
using namespace std;
int T, n, k, x;
struct node {
    int l, r;
    string s;
}p[20];
int main() {
    p[1].l = 0xcfcfcfcf, p[1].r = 1199, p[1].s = "Newbie";
    p[2].l = 1200, p[2].r = 1399, p[2].s = "Pupil";
    p[3].l = 1400, p[3].r = 1599, p[3].s = "Specialist";
    p[4].l = 1600, p[4].r = 1899, p[4].s = "Expert";
    p[5].l = 1900, p[5].r = 2099, p[5].s = "Candidate master";
    p[6].l = 2100, p[6].r = 2299, p[6].s = "Master";
    p[7].l = 2300, p[7].r = 2399, p[7].s = "International master";
    p[8].l = 2400, p[8].r = 2599, p[8].s = "Grandmaster";
    p[9].l = 2600, p[9].r = 2999, p[9].s = "International grandmaster";
    p[10].l = 3000, p[10].r = 0x3f3f3f3f, p[10].s = "Legendary grandmaster";
    scanf("%d", &T);
    while (T -- ) {
        scanf("%d%d", &n, &k);
        string s1, s2;
        for (int i = 1; i <= n; i ++ ) {
            int rate = k;
            scanf("%d", &x);
            k += x;
            for (int i = 1; i <= 10; i ++ ) {
                if (p[i].l <= k && p[i].r >= k) s1 = p[i].s;
                if (p[i].l <= rate && p[i].r >= rate) s2 = p[i].s;
            }
            if (s1 != s2) cout << s2 << " -> " << s1 << endl;
        }
        cout << s1 << endl;
    }
    return 0;
}

L
如果最后一位是\(a\),直接删除最后一位输出s
如果最后一位不是\(a\),最后一位减1,用\(z\)填充剩下的位数直到\(m\)

#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int main() {
    cin >> n >> m >> s;
    if (s[s.size() - 1] == 'a')
        s = s.substr(0, s.size() - 1);
    else {
        char c = s[s.size() - 1];
        c --;
        s = s.substr(0, s.size() - 1);
        s += c;
        while (s.size() < m)
            s += "z";
    }
    cout << s << endl;
    return 0;
}


这篇关于The 2021 Zhejiang University City College Freshman Programming Contest的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程