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\n";
    else
        cout << "Lost\n";
}

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比赛时没做就先鸽一下了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值