[Codeforces730A. Toda 2] STL模拟+Skills

[Codeforces730A. Toda 2] STL模拟+Skills

题目链接[Codeforces730A. Toda 2]
题意描述:有一个长度为 N 的数列r1,r2,,rn,每次操作可以从中选 2~min{5,N} 个数字,然后对选中的数字的 ri 全部减一,当 ri 为0时,减一还是 0 。经过上面一系列操作之后,可以让数列中每个ri都相等。求让数列所有元素相等并且元素的值尽可能大,变换的步数没有要求。
解题思路:利用multiset进行模拟。让每次只放2个或者3个数字。不去考虑放4个或者放5个。这样模拟起来就轻松多了。。

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100 + 5;
const int INF = 0x3f3f3f3f;

struct SNode {
    int r, id;
    SNode() {}
    SNode(int r, int id) : r(r), id(id) {}
    bool operator < (const SNode& e) const {
        return r > e.r;
    }
};

int N;
vector<string> Ans;
multiset<SNode> S;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    S.clear();
    Ans.clear();
    cin >> N;
    for (int i = 0, r; i < N; i++) {
        cin >> r;
        S.insert(SNode(r, i));
    }
    while (S.begin()->r != S.rbegin()->r) {
        int sz = S.size(), num = 2;
        if(S.count(*S.begin()) == 3) num ++;

        string buf(N, '0');
        vector<SNode> ar(num);
        for (int i = 0; i < num; i++) {
            SNode p = *S.begin(); S.erase(S.begin());
            buf[p.id] = '1';
            p.r = max(p.r - 1, 0);
            ar[i] = p;
        }
        S.insert(ar.begin(), ar.end());
        Ans.push_back(buf);
    }
    cout << S.begin()->r << "\n" << Ans.size() << "\n";
    copy(Ans.begin(), Ans.end(), ostream_iterator<string>(cout, "\n"));
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值