1 条题解

  • 0
    @ 2026-11-2 13:31:34

    分巧克力(Chocolate) 题解

    思路分析

    按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。

    参考代码

    #include <iostream>
    #include <vector>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        long long H, W;
        int N;
        if (!(cin >> H >> W >> N)) return 0;
        vector<long long> cnt(31, 0);
        for (int i = 0; i < N; ++i) {
            int a;
            cin >> a;
            cnt[a]++;
        }
        long long need = 0;
        for (int k = 30; k >= 0; --k) {
            need = need * 4 + cnt[k];
            long long cap = (H >> k) * (W >> k);
            if (need > cap) {
                cout << "No\n";
                return 0;
            }
        }
        cout << "Yes\n";
        return 0;
    }
    
    • 1

    信息

    ID
    8671
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者