• AtCoder Beginner Contest 088


    A - Infinite Coins

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, a;
    int main() {
        cin >> n >> a;
        if (n <= a)
            cout << "Yes" << endl;
        else {
            for (int i = 0; i <= a; i++) {
                if ((n - i) % 500 == 0) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            cout << "No" << endl;
            return 0;
        }
        return 0;
    }
    

    B - Card Game for Two

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, a[N];
    int main() {
        cin >> n;
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        int sum1 = 0, sum2 = 0;
        int k = 1;
        for (int i = n - 1; i >= 0; i--) {
            if (k) {
                sum1 += a[i];
                k = 0;
            } else {
                sum2 += a[i];
                k = 1;
            }
        }
        cout << sum1 - sum2 << endl;
        return 0;
    }
    
    

    C - Takahashi's Information

    给出一个3x3的数组C,问能否找到6个数a1 b1 a2 b2 a3 b3,使得(C_{i,j}==a_i+b_j)

    其中所有的数都在0-100之内

    因为数据范围很小,足以支持O(n^3)的算法,所以直接枚举a,去计算b,最后看能不能符合条件即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int a[3][3];
    int main() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cin >> a[i][j];
            }
        }
        for (int a1 = 0; a1 <= 100; a1++) {
            int b1 = a[0][0] - a1;
            if (b1 < 0) break;
            for (int a2 = 0; a2 <= 100; a2++) {
                int b2 = a[1][1] - a2;
                if (b2 < 0) break;
                if (a1 + b2 != a[0][1]) continue;
                if (a2 + b1 != a[1][0]) continue;
                for (int a3 = 0; a3 <= 100; a3++) {
                    int b3 = a[2][2] - a3;
                    if (b3 < 0) break;
                    if (a1 + b3 != a[0][2]) continue;
                    if (a2 + b3 != a[1][2]) continue;
                    if (a3 + b1 != a[2][0]) continue;
                    if (a3 + b2 != a[2][1]) continue;
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
        cout << "No" << endl;
        return 0;
    }
    
    

    D - Grid Repainting

    一个NxM的矩阵,要求从(1,1)点走到(n,m)点,只能走白块

    现在可以在走之前将某些白块变成黑块,问最多能将多少白块变成黑块

    直接求最短路,然后保留最短路,剩下的白块全部变成黑色即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 50 + 5;
    typedef long long LL;
    int n, m;
    char mp[N][N];
    int vis[N][N];
    int f[2][4] = {0, 0, 1, -1, 1, -1, 0, 0};
    int main() {
        cin >> n >> m;
        int num = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> mp[i][j];
                if (mp[i][j] == '.') num++;
            }
        }
        queue<int> q;
        q.push(1);
        q.push(1);
        q.push(1);
        int res = -1;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            int y = q.front();
            q.pop();
            int step = q.front();
            q.pop();
            if (x == n && y == m) {
                res = step;
                break;
            }
            if (vis[x][y]) continue;
            vis[x][y] = 1;
            for (int i = 0; i < 4; i++) {
                int xx = x + f[0][i];
                int yy = y + f[1][i];
                if (xx >= 1 && xx <= n && yy >= 1 && yy <= m &&
                    (vis[xx][yy] == 0) && (mp[xx][yy] == '.')) {
                    q.push(xx);
                    q.push(yy);
                    q.push(step + 1);
                }
            }
        }
        if(res!=-1){
            cout << num - res << endl;
        }
        else
            cout << -1 << endl;
        return 0;
    }
    
  • 相关阅读:
    prometheus client_golang使用
    etcd相关知识
    基于kubernetes v1.17部署dashboard:v2.0-beta8
    浅谈 Linux namespace
    使用kubeadm部署K8S v1.17.0集群
    和我一步步部署 kubernetes 集群
    go语言开发(二)---变量
    Golang学习笔记(一)-Go语言环境安装以及运行代码
    pycharm中设置pylint工具
    keeplive使用
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14386884.html
Copyright © 2020-2023  润新知