L1-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

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

栈限制

8192 KB

思路:就是把一个学校的所有人拉成一整条,然后行是学校,列是队员,这样就是竖着一列一列输入编号就可以了,在输入的时候稍微注意一下,如果有同一个学校的人挨着了,就让他们隔开一个位置就好了

cpp 复制代码
#include "bits/stdc++.h"
using namespace std;
int a[200][200] = {0}, b[200]; 
int main(){
	int n;
	cin>>n;
	int maxx = -1;
	for(int i = 1; i <= n; i ++){
		cin>>b[i];
		
		b[i] *= 10;
		maxx = max(maxx, b[i]);
	}
	int cnt = 1;
	int ans = 0;
	for(int i = 1; i <= maxx; i ++){
		for(int j = 1; j <= n; j ++){
			if(b[j] >= i)
				a[j][i] = cnt ++;
		}
	}
	for(int i = 1; i <= n; i ++){
		cout<<"#"<<i<<endl;
		for(int j = 1; j <= b[i]; j ++){
			if(j > 1 && (a[i][j] - a[i][j - 1]) <= 1){
				a[i][j] = a[i][j - 1] + 2;
				cout<<a[i][j];
				
				
			} 
			else cout<<a[i][j];
			if(j % 10 < 10 && j % 10 != 0) cout<<" ";
			else if(j != b[i]) cout<<endl;
		}
		if(i != n) cout<<endl;
	}
	return 0;
}
相关推荐
房开民4 小时前
c++总结
java·开发语言·c++
好大哥呀4 小时前
C++ 多态
java·jvm·c++
阿豪学编程5 小时前
LeetCode724.:寻找数组的中心下标
算法·leetcode
墨韵流芳5 小时前
CCF-CSP第41次认证第三题——进程通信
c++·人工智能·算法·机器学习·csp·ccf
hz_zhangrl5 小时前
CCF-GESP 等级考试 2026年3月认证C++五级真题解析
c++·青少年编程·程序设计·gesp·c++五级·gesp2026年3月·gesp c++五级
Σίσυφος19005 小时前
C++ 多肽经典面试题
开发语言·c++·面试
csdn_aspnet6 小时前
C# 求n边凸多边形的对角线数量(Find number of diagonals in n sided convex polygon)
开发语言·算法·c#
凌波粒6 小时前
LeetCode--349.两个数组的交集(哈希表)
java·算法·leetcode·散列表
crescent_悦7 小时前
C++:The Largest Generation
java·开发语言·c++
paeamecium7 小时前
【PAT甲级真题】- Student List for Course (25)
数据结构·c++·算法·list·pat考试