zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 087

    A - Buying Sweets

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int a, b, x;
    int main() {
        cin >> x >> a >> b;
        x-=a;
        cout << x % b << endl;
        return 0;
    }
    

    B - Coins

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int a, b, c, x;
    int main() {
        cin >> a >> b >> c >> x;
        int res = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    if (i * 500 + j * 100 + k * 50 == x) res++;
                }
            }
        }
        cout << res << endl;
        return 0;
    }
    

    C - Candies

    给出一个2xN的矩阵,问从左上角走到右下角能获得的权值最大是多少

    类似数塔模型的做法,推一下即可

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

    D - People on a Line

    给出n个人,他们都有一个权值,现在给出m个说法,每个说法代表第y个人比第x个人大d,问这m个说法是否能够自洽

    带权并查集裸题

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, m;
    int f[N], d[N];
    int findf(int x) {
        if (f[x] == x) return x;
        int tmp = findf(f[x]);
        d[x] += d[f[x]];
        return f[x] = tmp;
    }
    void Union(int x, int y, int w) {
        int fx = findf(x), fy = findf(y);
        if (fx != fy) {
            f[fy] = fx;
            d[fy] = w - d[y] + d[x];
        }
    }
    
    int main() {
        cin >> n>>m;
        for (int i = 0; i <= n; i++) f[i] = i;
        int flag = 0;
        for (int i = 0; i < m; i++) {
            int x, y, w;
            cin >> x >> y >> w;
            int fx = findf(x), fy = findf(y);
            if (fx == fy) {
                if (d[y] - d[x] != w) flag = 1;
            } else
                Union(x, y, w);
        }
        if (flag) cout << "No" << endl;
        else
            cout << "Yes" << endl;
    
        return 0;
    }
    
  • 相关阅读:
    如何监控IT正常运行时间?
    系统扩展正在取代macOS内核扩展,这会对您有何影响?
    IT管理员需要的10大网络工具
    自动化管理员工生命周期,集成Ultipro
    OpManager MSP:ManageEngine的新型MSP重点网络监控解决方案
    vue中axios的使用
    vue中axios的介绍
    移动端适配--关于根元素font-size和rem
    JavaScript---数组去重
    array数组的方法
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14387547.html
Copyright © 2011-2022 走看看