0
点赞
收藏
分享

微信扫一扫

天梯赛座位分配(轮盘转)

吃面多放酱 2022-03-16 阅读 61

题目
 

#include <bits/stdc++.h>

using namespace std;
int n;
int w[110][110];
int a[110][110];

int main()
{
	cin >> n;
	int maxx = 0;
	for (int i = 0; i < n; ++i)
	{
		int temp;
		cin >> temp;
		if (maxx < temp)
			maxx = temp;
		//标记需要更新的值	
		for (int j = 0; j < temp * 10; ++j)
		{
			w[i][j] = 1;
		}
	}
	
	int flag = -1, num = 1;
	//用最大的次数来限制 
	for (int i = 0; i < maxx * 10; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			//这一步有点像跳步,在多个数据之间来回跳步,但是只需要一个flag 
			if (w[j][i])
			{
				if (flag != j)
				{
					flag = j;
					a[j][i] = num++;
				}
				else if (flag == j)
				{
					num++;
					a[j][i] = num++;
				}
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << "#" << i + 1 << endl;
		//这一步输出操作,对于空格和换行很好的诠释了什么叫做想法 
		for (int j = 0; j < maxx * 10; ++j)
		{
			if (a[i][j] && (j + 1) % 10 == 0)
			{
				cout << a[i][j] << endl;
			}
			else if (a[i][j] && (j + 1) % 10)
			{
				cout << a[i][j] << ' ';
			}
		} 
	}
	
	return 0;
} 


 

举报

相关推荐

0 条评论