当前位置:网站首页>L1-049 天梯赛座位分配 (20 分)
L1-049 天梯赛座位分配 (20 分)
2022-04-21 10:00:00 【WTXYL】
天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情。为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位参赛选手。令每校选手排成一列纵队,第 i+1 队的选手排在第 i 队选手之后。从第 1 所学校开始,各校的第 1 位队员顺次入座,然后是各校的第 2 位队员…… 以此类推。如果最后只剩下 1 所学校的队伍还没有分配座位,则需要安排他们的队员隔位就坐。本题就要求你编写程序,自动为各校生成队员的座位号,从 1 开始编号。
输入格式:
输入在一行中给出参赛的高校数 N (不超过100的正整数);第二行给出 N 个不超过10的正整数,其中第 i 个数对应第 i 所高校的参赛队伍数,数字间以空格分隔。
输出格式:
从第 1 所高校的第 1 支队伍开始,顺次输出队员的座位号。每队占一行,座位号间以 1 个空格分隔,行首尾不得有多余空格。另外,每所高校的第一行按“#X”输出该校的编号X,从 1 开始。
输入样例:
3
3 4 2
输出样例:
#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 <iostream>
using namespace std;
const int N = 110;
int n, x, rest_cnt; // rest_cnt 为还有未分配学生的学校数量
// 各个学校的学生数量 所有学生的座号 各个学校已分配座号的学生数量
int stu_cnt[N],all_no[N][N], cnts[N];
int main(){
cin >> n;
rest_cnt = n;
for(int i = 1; i <= n; i ++){
cin >> x;
stu_cnt[i] = x * 10;
}
int no = 1;
while(rest_cnt){
for(int i = 1; i <= n; i ++){
int & cnt = cnts[i];
if(stu_cnt[i] > cnt){
all_no[i][cnt ++] = no;
if(rest_cnt == 1)no += 2;
else no ++;
if(cnt == stu_cnt[i]) rest_cnt --;
}
}
}
//输出
for(int i = 1; i <= n; i ++){
cout << "#" << i << endl;
for(int j = 0; j < stu_cnt[i]; j ++){
if(j != 0 && j % 10 == 0) cout << endl;
if(j % 10 != 0) cout << " ";
cout << all_no[i][j];
}
cout << endl;
}
}
版权声明
本文为[WTXYL]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46891900/article/details/124216301
边栏推荐
- Generate training set and verification set (Yolo) by using existing label files
- gunicorn使用----服务端项目部署
- CentOS下Docker中安裝MySQL
- 【手拉手 带你准备电赛】使用定时器中断更改PWM占空比
- [note] package XML file syntax record
- 2022危险化学品经营单位主要负责人上岗证题库及模拟考试
- Transaction isolation level and mvcc
- [hand in hand to prepare you for the electric game] use the timer interrupt to change the PWM duty cycle
- 常用文本处理命令
- Gunicorn usage - server project deployment
猜你喜欢
随机推荐
SQL question set [(2)]
SQL题集[(2)]
Write table of MySQL Foundation (create table)
部署web服务器,亲身经历
VS 2019中使用qt
Operation of simulated examination platform of special operation certificate examination question bank for safety production management personnel of hazardous chemical production units in 2022
String match KMP BF
Exon bed file acquisition
About incorrect deletion of operations in notes
Various methods provided by C string
Ansible_03_高级playbook
[词性] 二十三、情态动词 2 [ have to ] [ ought to ] [ dare ] [ be able to ] [ needn‘t ]
[hand in hand to prepare you for the video game] recent summary
When uniapp encounters rolling penetration, a clever solution~
Transaction isolation level and mvcc
【数据库第十二次作业-存储过程】
【无标题】
【愚公系列】2022年04月 微信小程序-地图的使用之面聚合
大/小根堆
[fluent topic] 124 summary of daily problems (III) two or three things about custom dialog








