AtCoder Beginner Contest 047(4/4)

Fighting over Candies

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Snuke's Coloring 2 (ABC Edit)

模拟

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, q;
    cin >> n >> m >> q;
    int minx = 0, miny = 0, maxx = n, maxy = m;
    while (q--) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            minx = max(minx, x);
        } else if (a == 2) {
            maxx = min(maxx, x);
        } else if (a == 3) {
            miny = max(miny, y);
        } else {
            maxy = min(maxy, y);
        }
    }
    int x = maxx - minx, y = maxy - miny;
    if (x <= 0 || y <= 0) {
        cout << "0\n";
    } else {
        cout << x * y << '\n';
    }
    return 0;
}

1D Reversi

找不同的边界数即可

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();
    int ans = 0;
    for (int i = 0; i < len; i++) {
        if (i > 0 && s[i] != s[i - 1]) {
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

An Invisible Hand

记录后缀最大值即为未来要卖的价钱,找出售价-进价的最大值,如果有多个不同的方案,则所有的方案里都需要改变,每次变化只需要改变1即可

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, t;
    cin >> n >> t;
    t >>= 1;
    vector<int> a(n + 1), maxx(n + 1), cnt(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    priority_queue<int, vector<int>, less<int>> q;
    maxx[n] = -0x3f3f3f3f;
    q.push(a[n]);
    for (int i = n - 1; i >= 1; i--) {
        maxx[i] = q.top();
        q.push(a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cnt[i] = maxx[i] - a[i];
    }
    int max1 = *max_element(cnt.begin(), cnt.end());
    if (max1 <= 0) {
        cout << 0 << '\n';
    } else {
        for (int i = 1; i <= n; i++) {
            if (cnt[i] == max1) {
                ans++;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值