题目链接
水题,模拟就行
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[150], b[150];//a记录每个学校有几个队,b记录每个学校有几个人,由题意可知b[i]=a[i]*10
bool book[150];//标记该学校学生是否全部分配完
vector<int> e[150];//存学生座位号
int main(int argc, char const *argv[]) {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> a[i];
b[i] = a[i] * 10;
}
int ans = t, k = 1, x = 1;//k模拟学校数,x模拟座位号
while (ans) {
if (book[k] == 0) {//如果该学校学生没有全部分配完成
e[k].push_back(x);//压入
b[k]--;//该学校学生数-1(已经分配完成一位)
if (ans == 1)//如果最后还剩一个学校的话座位要隔开坐
x += 2;
else
x++;
}
if (b[k] == 0 && book[k] == 0) {//如果有学校学生全部分配完毕
book[k] = 1;//标记该学校已经完成分配
ans--;//学校数-1
}
k++;//学校数+1
if (k > t) k = 1;//保证学校数合法
}
for (int i = 1; i <= t; i++) {//输出
printf("#%d\n", i);
for (int j = 0; j < a[i] * 10; j++) {
if (j % 10 == 0)
printf("%d", e[i][j]);
else
printf(" %d", e[i][j]);
if ((j + 1) % 10 == 0) printf("\n");
}
}
return 0;
}