[Codeforces730A. Toda 2] STL模拟+Skills
题目链接:[Codeforces730A. Toda 2]
题意描述:有一个长度为
N
的数列
解题思路:利用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;
}