您经营一家小剧院,每个月都会有顾客寄来预售票请求。您需要处理这些票务请求,或者告诉他们他们的派对将坐在哪里,或者向顾客解释为什么您无法完成他们的订单。
您在填写订单时需要遵守一些规则:
- 尽可能多地完成订单
- 让聚会尽可能靠近前面。
- 如果剧院没有足够的座位来举办派对,请告诉他们“抱歉,我们无法举办您的派对。”
- 每一方都必须坐在一个区域的单排中。如果他们不适合,请告诉他们“调用 split 方”。
您的程序必须解析剧院布局和门票请求列表,并按照与请求相同的顺序生成门票列表或说明。
剧院布局由 1 行或多行组成。每行由 1 个或多个以空格分隔的部分组成。
剧院布局后,有一个空行,后面是1个或多个剧院请求。剧院请求由名称后跟一个空格和请求的票数组成。
示例输入:
6 6
3 5 5 3
4 6 6 4
2 8 8 2
6 6
Smith 2
Jones 5
Davis 6
Wilson 100
Johnson 3
Williams 4
Brown 8
Miller 12
您的程序必须以与请求相同的顺序向标准输出生成结果,其中包括请求票证的人的姓名以及票证的行和部分或解释“抱歉,我们无法处理您的方”或“调用 split 方。”
示例输出:
```
Smith Row 1 Section 1
Jones Row 2 Section 2
Davis Row 1 Section 2
Wilson Sorry, we can't handle your party.
Johnson Row 2 Section 1
Williams Row 1 Section 1
Brown Row 4 Section 2
Miller Call to split party.
最佳答案
你也许应该写下你到目前为止尝试过的东西。无论如何,我认为可以使用以下算法解决。您可以编写相同的代码。
1. Keep track of total_seats.
2. Sort the theater requests based on the number of seats needed (since filling more orders is the priority).
3. For each request :
if request < total_seats :
For each row:
if request < seats_in_row:
total_seats -= seats
update theater_seat[row][column]
else:
Call to split party.
else:
Sorry, we can't handle your party.
关于arrays - 如何在剧院中找到二维阵列的最佳座位安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48372108/