• 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) << '
    ';
        }
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    EOJ 2743 Stock Exchange
    POJ-3468 A Simple Problem with Integers
    EOJ-1104 bitmap
    【转】旋转卡壳——凸多边形间对踵点对(定义)
    Ring 3层枚举进程的四种方法
    XX-Net项目,免费浏览谷歌的伟大项目
    浅析Java中的内存机制
    Ubuntu下eclipse中安装Scala插件
    注入(5)---导入表注入(HookINT)
    Linux下MySQL导入文件出错ERROR 1290 (HY000)
  • 原文地址:https://www.cnblogs.com/RioTian/p/15035753.html
Copyright © 2020-2023  润新知