AtCoder Beginner Contest 048(4/4)

AtCoder *** Contest

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<string> a(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    cout << "A" << a[1][0] << "C\n";
    return 0;
}

Between a and b ...

计算出[a,b]内能被x整除的上下界

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL a, b, x;
    cin >> a >> b >> x;
    LL c = (a + x - 1) / x, d = b / x;
    cout << max(0LL, d - c + 1) << '\n';
    return 0;
}

Boxes and Candies

贪心,如果当前糖果和前一个糖果的总和大于x,则优先减少当前糖果的数量,多余的再减少前一个糖果的数量,保证对后面的计算更有利

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    LL x;
    cin >> n >> x;
    vector<LL> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] + a[i - 1] > x) {
            ans += (a[i] + a[i - 1] - x);
            if (a[i] + a[i - 1] - x >= a[i]) {
                a[i] = 0;
            } else {
                a[i] -= a[i] + a[i - 1] - x;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

An Ordinary Game

博弈,因为只能拿走中间的字符,并且保证相邻的两个字符没有相同的,考虑极端情况ababa,此时两头字符相等,先手拿任何一个都不可以所以后手赢,再有ababab,两头字符不相等,先手拿任何一个都不可以,后手仍然赢。考虑一般情况,如果两头字符相等,最多就是拿完所有中间n-2个字符,所以如果字符长度为奇数,后手赢,否则先手赢,如果两头字符不相等,最多也是拿完所有中间n-2个字符,最后的情况是没有字符可以拿,而不是相邻两个字符相等,所以字符长度为奇数,先手赢,否则后手赢

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int len = s.size();
    if (s[0] == s[len - 1]) {
        if (len % 2 == 0) {
            cout << "First\n";
        } else {
            cout << "Second\n";
        }
    } else {
        if (len % 2 == 0) {
            cout << "Second\n";
        } else {
            cout << "First\n";
        }
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值