当前位置:网站首页>L1-049 ladder race seat allocation (20 points)
L1-049 ladder race seat allocation (20 points)
2022-04-22 04:18:00 【WTXYL】
There are a large number of players in the ladder race every year , Make sure that all members of the same school are not adjacent , The allocation of seats becomes a more troublesome thing . So we have the following strategies : Suppose that there is N Schools compete , The first i Schools have M[i] team , Every team 10 Contestants . Line up the players of each school , The first i+1 The players of the team are in i After the team . From 1 Schools start , The first of each school 1 Members of the team were seated in sequence , And then there's the number 2 Team members …… And so on . If there is only 1 The school team has not allocated seats yet , They need to arrange their team members to sit in separate seats . This question asks you to write a program , Automatically generate the seat number of the team members for each school , from 1 Numbered starting .
Input format :
Enter the number of colleges and universities in a row N ( No more than 100 The positive integer ); The second line gives N No more than one. 10 The positive integer , Among them the first i The number corresponds to the i The number of participating teams in Universities , Numbers are separated by spaces .
Output format :
From 1 The number of colleges and universities 1 Team start , Output the seat number of the team member in sequence . Each team has a line , Between seat numbers 1 Space separation , There must be no extra space at the beginning and end of the line . in addition , Press... On the first line of each university “#X” Output the number of the school X, from 1 Start .
sample input :
3
3 4 2
sample output :
#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
Code :
#include <iostream>
using namespace std;
const int N = 110;
int n, x, rest_cnt; // rest_cnt For the number of schools with unassigned students
// The number of students in each school Seat numbers of all students Number of students assigned seat numbers in each school
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 --;
}
}
}
// Output
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://yzsam.com/2022/04/202204211000289988.html
边栏推荐
- 02 - sparksql
- [machine learning] long and short term memory network (LSTM)
- 24 pictures to conquer border image
- DOM event flow and event delegation
- 交通行业提升数据利用效率的核心是做好数据交换与共享
- Cursor iterator mode
- Spark quick start series (5) | spark environment construction - standalone (2) configuring history log server
- PowerDesiPowerDesigner导入sql 不显示表关联关系 怎么解决
- matplotlib画3dbox
- Open source culture is still shining - in the openeuler community, with technology and idea, you are the protagonist
猜你喜欢

05-Aggregation

Tutorial - sumolympics

智慧用电安全管理系统

交通行业提升数据利用效率的核心是做好数据交换与共享

SR-TE Policy(思科)----补充

Tensorflow error: returned a result with an error set solution

sqlilabs(25a-26)

What level have you learned from your pointer? Eight pointer questions let you deepen your understanding of pointer (Part 2) - O -

Websocket learning

Why can sqlmap run the issue table but not the fields
随机推荐
01-Read&Write
Class component details
Sumo tutorial - Manhattan
[golang] force buckle leetcode - 657 Whether the robot can return to the origin (simulation)
LeetCode 63. 不同路径 II
Optimisation des performances des pages Web
Experts have information | Zhang Zuyou: Tencent cloud devsecops practice and open source governance exploration
Exploring Presto SQL Engine (2) - Analysis of join
Web 安全之 XSS 攻击原理/分类/防御 详解
Alibaba cloud EMAS product dynamics in March
Where is the whole house intelligence that Huawei, Haier Zhijia and Xiaomi are all doing?
What is the decimal type in MySQL?
Pgpool II 4.3 Chinese Manual - introductory tutorial
[recent force deduction] Fibonacci sequence + realizing queue with two stacks + printing linked list from end to end
04-Functions
Browser overview local cache cookies, etc
容联七陌赋能企业智能化服务,重新定义客服价值
Solution to write protection of WinXP U disk that cannot be copied
XSS attack principle / classification / defense of Web Security
Machine learning series (5)_ Feature Engineering 03 small case of carbon emission