PAT1014

Suppose a bank has N windows open for service.windows

一個銀行有N個服務的窗口數據結構

There is a yellow line in front of the windows which devides the waiting area into two parts.ide

在每一個窗口前面都一根黃線用來劃分等待區的兩個部分測試

The rules for the customers to wait in line are:spa

對於顧客來講等待線的規則是這樣的orm

  • The space inside the yellow line in front of each window is enough to contain a line with M customers.

在每一個窗口前面的黃線之內可以包含M個顧客隊列

Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line.ci

所以,當全部N條線,全部的顧客中第N*M+1位顧客必須在黃線後等待input

  • Each customer will choose the shortest line to wait in when crossing the yellow line.

當越過黃線以後,每一個顧客將會選擇最短的隊伍去等待。it

If there are two or more lines with the same length, the customer will always choose the window with the smallest number.

若是有兩個或者更多的一樣長度的隊伍,顧客會老是會選擇更小編號的隊伍。

  • Customer[i] will take T[i] minutes to have his/her transaction processed.

顧客i將會花費Ti分鐘處理本身的交易流程

  • The first N customers are assumed to be served at 8:00am.

前面N個顧客假定從早上8點開始被服務

Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.

如今給出每一個顧客的交易時間,要求你求出每一個顧客完成業務的準確時間

For example, suppose that a bank has 2 windows and each window may have 2 custmers waiting inside the yellow line.

例如,一個銀行有兩個窗口,每一個一個窗口能有兩個顧客等在黃線內

There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively.

如今我5位顧客,花費的時間分別是12643

At 08:00 in the morning, customer1 is served at window1 while customer2 is served at window2.

在早上8點,顧客1在窗口1,顧客2在窗口2

Customer3 will wait in front of window1 and customer4 will wait in front of window2.

顧客3等在窗口1,顧客4等在窗口2

Customer5 will wait behind the yellow line.

顧客5等在黃線後

At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now.

8點01分,顧客1完成了,顧客5進入線內,到了隊伍最短的窗口1

Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.

顧客2,在8點02離開,顧客4.。。。。。。。

Input

Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (<=20, number of windows), M (<=10, the maximum capacity of each line inside the yellow line), K (<=1000, number of customers), and Q (<=1000, number of customer queries).

每一個輸入文件包含一個測試用例,每一個測試用例由4個整數開始,N, M, K, Q

The next line contains K positive integers, which are the processing time of the K customers.

下面K個正整數表示K顧客花費的時間

The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.

最後一行Q個整數,表明那些想要詢問他們想要詢問他們到底花費了多少時間的人。顧客的編號從1到K

Output

For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.

對於q個顧客,打印一行時間,他完成的時間,格式是HH:MM,HH是08-17,MM是00-59。記住銀行天天17:00關門,對於那些不能再17:00完成的業務的,你須要輸出soory

Sample Input

2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7

Sample Output

08:07
08:06
08:10
17:00
Sorry
題目的意思已經很明顯了,銀行排隊,已經很明顯了,數據結構用隊列就好了,每一個窗口一個隊列,而後到時間了完成了出隊,然入隊,主要考驗模擬時的邏輯能力。用queue會簡單一些。
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息