Codeforces Round #778 (Div. 1 + Div. 2, based on Technocup 2022 Final Round) C. Alice and the Cake

C. Alice and the Cake
题意
你现在有一块蛋糕,你可以切n-1刀,且完后的两块,一块是x/2,一块是(x+1)/2,现在告诉你切完之后的有n块,并告诉你每一块的大小,现在问你能否得到蛋糕的初始大小,并且执行了n-1次操作后变为给你的蛋糕大小。
思路
首先,我们可以根据给你的蛋糕得到初始的蛋糕大小,然后我们现在可以模拟切蛋糕的方式,假设蛋糕的初始大小为sum,并且出现的大小为mp[x],那么我们可以从最初的大小开始切,没切一刀,判断且完后的两块蛋糕是否出现过,如果出现过,我们就不动这一块,转战另一块,否则就切这一块蛋糕,一分为二。

#include <bits/stdc++.h>

#define int long long

using namespace std;

void solve()
{
    int n; cin >> n;
    int sum = 0;
    vector<int> now, tmp;
    map<int, int> mp;

    int len = n;
    while (n --)
    {
        int x; cin >> x;
        sum += x;
        mp[x] ++;
    }

    now.push_back(sum);
    while (now.size() && len >= now.size() && len)
    {
        for (auto it : now)
            if (mp[it]) { mp[it] --; len --; }
            else
            {
                if (it >= 2) { tmp.push_back(it / 2); tmp.push_back((it + 1) / 2); }
                else tmp.push_back(1);
            }

        now = tmp;
        tmp.clear();
    }

    if (len) cout << "NO" << endl;
    else cout << "YES" << endl;
}

signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t --) solve();

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值