7-44 Seating Allocation for Ladder Tournament (20 points)
There are a large number of players participating in the Ladder Tournament every year. It is necessary to ensure that all members of the same school cannot be adjacent to each other. Seat allocation becomes a more troublesome task. To this end, we formulate the following strategy: Suppose there are N schools participating in a certain field, the i-th school has M[i] teams, and each team has 10 contestants. Make the players of each school line up in a column, and the players of the i+1th team are ranked after the players of the ith team. Starting from the first school, the first team member of each school will be seated in order, and then the second team member of each school... and so on. If there is only one school left and the team has not been assigned a seat, they need to arrange for their team members to sit in separate seats. This question requires you to write a program to automatically generate the seat numbers of the players for each school, starting from 1.
Input format:
Enter the number of universities N (a positive integer not exceeding 100) in one line; N positive integers not exceeding 10 are given in the second line, where the i-th number corresponds to the participating team of the i-th university Numbers, separated by spaces.
Output format:
Starting from the first team of the first college, output the seat numbers of the players in sequence. Each team occupies a line, and the seat numbers are separated by 1 space, and there must be no extra spaces at the beginning and end of the line. In addition, press "#X" on the first line of each college to output the school's number X, starting from 1.
Input example:
3
3 4 2
Output example:
#1
1 4 7 10 13 16 19 22 25 28
31 34 37 40 43 46 49 52 55 58
61 63 65 67 69 71 73 75 77 79
#2
2 5 8 11 14 17 20 23 26 29
32 35 38 41 44 47 50 53 56 59
62 64 66 68 70 72 74 76 78 80
82 84 86 88 90 92 94 96 98 100
#3
3 6 9 12 15 18 21 24 27 30
33 36 39 42 45 48 51 54 57 60
#include<bits/stdc++.h>
using namespace std;
int s[110][110],book[110][110],t[110];
int main(){
int n,mx=0;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&t[i]);
mx=max(mx,t[i]);
for(int j=0;j<t[i]*10;j++){
book[i][j]=1;//标记位置
}
}int sum=0,f=-1;
for(int i=0;i<mx*10;i++){
for(int j=0;j<n;j++){
if(book[j][i]){
if(f!=j)//判断最后一队分开坐
s[j][i]=++sum,f=j;
else {
sum+=2;
s[j][i]=sum;
}
}
}
}
for(int i=0;i<n;i++){
cout<<"#"<<i+1<<endl;
for(int j=0;j<=t[i]*10;j++){
//<=
if(j&&j%10==0)cout<<endl;
if(j%10==0&&s[i][j])cout<<s[i][j];
else if(j%10&&s[i][j])cout<<" "<<s[i][j];//else if
}
}
return 0;
}