模拟过程走一遍即可
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int M[N];
#define x first
#define y second
int main()
{
int n;
cin >> n;
int maxm = 0;
for(int i = 1; i <= n; ++ i)
{
cin >> M[i];
M[i] *= 10;
maxm = max(maxm, M[i]);
}
vector<int> res;
for(int i = 1; i <= maxm; ++ i)
{
for(int j = 1; j <= n; ++ j)
{
if(M[j] > 0) res.push_back(j);
-- M[j];
}
}
int cnt = 1;
vector<vector<int>> ans(n+1);
for(int i = 0; i < res.size(); ++ i)
{
if(i != res.size() - 1)
{
if(res[i + 1] == res[i])
{
ans[res[i]].push_back(cnt ++);
++ cnt;
}
else ans[res[i]].push_back(cnt ++);
}
else ans[res[i]].push_back(cnt ++);
}
for(int i = 1; i <= n; ++ i)
{
cout << "#" << i << endl;
for(int j = 0; j < ans[i].size(); ++ j)
cout << ans[i][j] << " \n"[j%10 == 9];
}
return 0;
}
标签:cnt,20,int,res,ans,back,++,049,L1
From: https://www.cnblogs.com/Frodnx/p/18390722