Code:
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define f(i,a,n) for(int i=a;i<n;++i)
#define ff(i,a,n) for(int i=a;i<=n;++i)
#define IN freopen("E:\\信竞\\信竞文件夹\\in_c.TXT","r",stdin);
const int INF=0x3f3f3f3f;
using namespace std;
typedef long long ll;
//
const int N=105;
vector<int> v[N];
int n,sum;
int a[N];
set<int> st;
int main(){
//IN
cin>>n;
ff(i,1,n){
cin>>a[i];
sum+=a[i];
}
sum*=10;
int pos=0;
int flag=-1,w=-1;
//设置w是因为我第一次该轮到它的时候,它的值可能已经加了好多了
ff(i,1,sum+1){
pos++;
if(pos==n+1)pos=1;//位置很苛刻
while(pos<=n && v[pos].size() == a[pos] * 10){
pos++;
}
if(pos==n+1)pos=1;//这得写2次,如果思维不够敏捷,就要多调试
if(st.size()!=n-1){
v[pos].push_back(i);
if(v[pos].size() == a[pos] * 10) st.insert(pos);
}
else {
w=i;
flag=pos;
break;
}
//debug(i)debug(pos)debug(st.size())
}
if(~flag){
int k=a[flag]*10-v[flag].size();
if(v[flag].size() && v[flag][v[flag].size()-1]==w-1)w++;
f(i,0,k){
v[flag].push_back(w);
w+=2;
}
}
ff(i,1,n){
cout<<"#"<<i<<endl;
for(int j=0; j < v[i].size(); j++){
if(j%10!=9)cout << v[i][j] << " ";
else cout << v[i][j] << endl;
}
}
return 0;
}
Hope the big guys can help to solve the QAQ