0

您经营一家小剧院,每个月都有顾客邮寄预售票的请求。您需要处理这些票务请求,或者告诉他们他们的派对将坐在哪里,或者向顾客解释您为什么不能完成他们的订单。

填写订单时,您需要遵守一些规则:

  1. 填写尽可能多的订单
  2. 让派对尽可能靠近前面。
  3. 如果剧院里没有足够的座位来举办派对,请告诉他们“抱歉,我们无法为您举办派对”。
  4. 每一方必须坐在一个单独的区域中的一排。如果他们不适合,告诉他们“呼叫分裂党”。

您的程序必须解析剧院布局和门票请求列表,并按照与请求相同的顺序生成门票或解释列表。

剧院布局由 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

您的程序必须以与请求相同的顺序将结果输出到标准输出,其中包含请求票证的人的姓名以及票证的行和部分或解释“抱歉,我们无法处理您的聚会”或“呼叫分裂党。”

样本输出:

```

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.
4

1 回答 1

1

你也许应该写下你到目前为止所做的尝试。无论如何,我认为可以使用以下算法解决。您可以编写相同的代码。

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. 
于 2018-01-24T10:21:24.863 回答