简体   繁体   English

如何在影院中找到2D阵列的最佳座位安排

[英]How to find the best seating arrangement in a theater for 2d array

You run a small theater and each month, you have patrons mail in requests for pre-sale tickets. 您经营一个小剧院,每个月都有顾客邮寄预售票的请求。 You need to process these ticket requests and either tell them where their party will sit or explain to the patron why you can't complete their order. 您需要处理这些票务请求,或者告诉他们他们的聚会将坐在哪里,或者向顾客解释为什么您无法完成他们的订购。

You have a few rules that you need to follow when you fill the orders: 填写订单时,您需要遵循一些规则:

  1. Fill as many orders as possible 尽可能多地填写订单
  2. Put parties as close to the front as possible. 将聚会尽可能靠近前台。
  3. If there are not enough seats available in the theater to handle a party, tell them "Sorry, we can't handle your party." 如果剧院中没有足够的座位来举行聚会,请告诉他们“对不起,我们无法处理您的聚会。”
  4. Each party must sit in a single row in a single section. 各方必须在同一部分中排成一行。 If they won't fit, tell them "Call to split party". 如果他们不适合,请告诉他们“致电参加聚会”。

Your program must parse a theater layout and a list of ticket requests and produce a list of tickets or explanations in the same order as the requests. 您的程序必须解析剧院布局和票证请求列表,并以与请求相同的顺序生成票​​证或说明列表。

The theater layout is made up of 1 or more rows. 剧院布局由1行或更多行组成。 Each row is made up of 1 or more sections separated by a space. 每行由1个或多个由空格分隔的部分组成。

After the theater layout, there is one empty line, followed by 1 or more theater requests. 剧院布局后,有一个空行,然后是1个或多个剧院请求。 The theater request is made up of a name followed by a space and the number of requested tickets. 剧院请求由名称,空格和请求的票数组成。

Sample input: 输入样例:

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

Your program must produce results to standard output in the same order as the requests, with the name of the person who requested the ticket and either the row and section of the ticket or the explanations "Sorry, we can't handle your party" or "Call to split party." 您的程序必须以与请求相同的顺序将结果生成到标准输出中,并带有请求票证的人的姓名以及票证的行和部分,或者说明“对不起,我们无法处理您的聚会”或“打电话去参加聚会。”

Sample output: 样本输出:

``` ```

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.

You should maybe write down what you have tried so far. 您也许应该写下到目前为止所做的尝试。 Anyway, I think it can be solved using the following algorithm. 无论如何,我认为可以使用以下算法解决。 You can code the same. 您可以编写相同的代码。

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. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM