zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 189 Personal Editorial

    第一次参加 AtCoder 的比赛,感觉还挺简单。

    比赛链接:https://atcoder.jp/contests/abc189

    A - Slot

    // Author : RioTian
    // Time : 21/01/23
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        string s;
        cin >> s;
        if (s[0] == s[1] && s[1] == s[2])
            cout << "Won
    ";
        else
            cout << "Lost
    ";
    }
    

    B - Alcoholic

    高桥(大家都喜欢的高桥同学)要喝酒了,现在有n中酒,如果高桥同学喝酒的量大于 (X ml)则会喝酒离开酒席。那么请输出高桥是在第几个酒上喝醉了,如果没有喝醉请输出 -1

    // Author : RioTian
    // Time : 21/01/24
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        int n, v, p, x;
        int sum = 0;
        cin >> n >> x;
        for (int i = 1; i <= n; ++i) {
            cin >> v >> p;
            sum += v * p;
            if (sum > x * 100) {
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
    

    C - Mandarin

    求最大连续序列和,但由于n比较小直接暴力即可。

    // Author : RioTian
    // Time : 21/01/24
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e5 + 10;
    int a[N];
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) cin >> a[i];
    
        int ans = 0;
        for (int l = 0; l < n; ++l) {
            int x = a[l];
            for (int r = l; r < n; ++r) {
                x = min(x, a[r]);
                ans = max(ans, x * (r - l + 1));
            }
        }
        cout << ans << endl;
    }
    

    D - Logical Expression

    如果 (S_i)AND 则 opt 设为 true,在之后只要 (f(S_1,...,S_N) = f(S_1,...,S_{N-1}))

    如歌 (S_i)OR 则 opt 设为 false,需要 (f(S_1,...,S_N) = 2^N + f(S_1,...,S_{N-1}))

    // Author : RioTian
    // Time : 21/01/24
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 100;
    
    ll dp[N][2];
    bool opt[N];
    string s;
    
    int main() {
        // freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> s;
    
            if (s[0] == 'A')
                opt[i] = true;
            else
                opt[i] = false;
        }
    
        dp[0][0] = dp[0][1] = 1;
        for (int i = 1; i <= n; ++i) {
            if (opt[i - 1]) {
                dp[i][0] = 2 * dp[i - 1][0] + dp[i - 1][1];
                dp[i][1] = dp[i - 1][1];
            } else {
                dp[i][0] = dp[i - 1][0];
                dp[i][1] = 2 * dp[i - 1][1] + dp[i - 1][0];
            }
        }
    
        cout << dp[n][1] << endl;
    }
    

    E,F比赛时没做就先鸽一下了

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    Redis单点登录
    MySQL有哪些存储引擎,各自的优缺点,应用场景
    MySQL慢查询优化、索引优化、以及表等优化总结
    Redis缓存和MySQL数据一致性方案详解
    Jenkies+github实现代码自动构建
    Python基础-day14-单元测试注册小例子
    Python基础-day13-unitest框架(Suite、runner)及生成报告,附带最新的HTMLTestRunnerNew.py文件
    Python基础-day11-继承和动态设置属性
    Python基础-day10-类的创建和调用
    Python基础-day03 字符串
  • 原文地址:https://www.cnblogs.com/RioTian/p/14320251.html
Copyright © 2011-2022 走看看