AtCoder Regular Contest 123 (A~C 三道好题)

比赛链接:Here

A - Arithmetic Sequence (good)

注意细节

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    ll x = 2 * b - a - c;
    ll k = (x >= 0 ? 0 : (1 - x) / 2);
    ll ans = x + 3 * k;
    cout << ans << endl;
}

B - Increasing Triples (good)

大根堆优先队列

using PQ = priority_queue<int, vector<int>, greater<int>>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;

    PQ A, B, C;
    for (int i = 0, x; i < n; ++i) {cin >> x; A.push(x);}
    for (int i = 0, x; i < n; ++i) {cin >> x; B.push(x);}
    for (int i = 0, x; i < n; ++i) {cin >> x; C.push(x);}

    int a, b;
    int ans = 0;
    while (!A.empty()) {
        a = A.top(); A.pop();

        while (!B.empty() and B.top() <= a)B.pop();
        if (B.empty() )break;
        b = B.top(); B.pop();

        while (!C.empty() and C.top() <= b)C.pop();
        if (C.empty()) break;
        C.pop();

        ++ans;
    }
    cout << ans ;
}

C - 1, 2, 3 - Decomposition (good)

给你一个数,让你分解成不含0的四进制之和,求最少分解成多少个?


从高位到低位思考,每一位有两种情况,一种借一给低位,另一种不借。含高位构造数数目小于等于含低位的构造数数目.

int solve(ll n) {
    if (n == 0)return 0;
    if (n < 10)return (n - 1) / 3 + 1;
    ll mi = 0;
    ll pi = n, pa, pb;
    pb = solve(pi / 10 - 1);
    pa = solve(pi / 10);
    if (pa > pi % 10)return max(pb, (pi % 10 + 10 - 1) / 3 + 1);
    return min(max(pa, (pi % 10 - 1) / 3 + 1), max(pb, (pi % 10 + 10 - 1) / 3 + 1));
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int _; for (cin >> _; _--;) {
        ll n; cin >> n;
        cout << solve(n) << '\n';
    }
}
posted @   RioTian  阅读(142)  评论(1编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
历史上的今天:
2020-07-20 signed main 和 int main 的区别
2020-07-20 Codeforces Round #656 (Div. 3)部分题解
点击右上角即可分享
微信分享提示

📖目录