ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AtCoder Beginner Contest 189 Personal Editorial

2021-01-24 11:04:23  阅读:190  来源: 互联网

标签:AtCoder cout Beginner Contest int nullptr cin long tie


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

标签:AtCoder,cout,Beginner,Contest,int,nullptr,cin,long,tie
来源: https://www.cnblogs.com/RioTian/p/14320251.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有