1. 程式人生 > >【PAT1014】 Waiting in Line (30) queue模擬排隊

【PAT1014】 Waiting in Line (30) queue模擬排隊

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:

  • The space inside the yellow line in front of each window is enough to contain a line with M customers. 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.
  • Each customer will choose the shortest line to wait in when crossing the yellow line. 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.
  • The first N customers are assumed to be served at 8:00am.

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. At 08:00 in the morning, customer1

 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.

At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.

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

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

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.

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.

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

相關推薦

PAT1014 Waiting in Line (30) queue模擬排隊

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules fo

1014. Waiting in Line (30)

not posit con red bsp ransac blog else where Suppose a bank has N windows open for service. There is a yellow line in front of the window

[PAT甲級]1014. Waiting in Line (30)(銀行排隊辦理業務結束時間 佇列的應用)

1014. Waiting in Line (30) 原題連結 相似題目 1017. Queueing at Bank (25) Suppose a bank has N windows open for service. There is a yello

1014 Waiting in Line30 分)C++實現(已AC)

題目 題目連結:https://pintia.cn/problem-sets/994805342720868352/problems/994805498207911936 思路: 建立一個視窗列表,每個列表維護一個M長度的佇列, 以及佇列末尾的人服務結束的時間, 逐個插入客戶

PAT 1014 Waiting in Line30 分)燚

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two part

模擬_1014 Waiting in Line30 分)

1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which

PAT-1014 Waiting in Line30 分)

1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the wa

1014 Waiting in Line30 分)

Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rul

PAT 1014 Waiting in Line30 分)

1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which dev

PAT (Advanced Level) 1014 Waiting in Line30 分)

1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the wa

**甲級PAT1014 Waiting in Line (已經通過全部測試,找到一個奇怪的坑但是不知道為什麼,跪求大佬回覆)

1014 Waiting in Line (30)(30 分) Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devid

IEIE對line-height 失效的的解決方案

microsoft san htm round ffffff eight overflow 解決方案 ack 微軟的IE9 + Extjs3.1 確實頭疼。在使用了line-height:20px 的Tree的樣式,可是一直沒有生效, 以下給出3中解決方式: 方案1、

CF845FGuards In The Storehouse 插頭DP

namespace return scan printf swa 超過 障礙 body pri 【CF845F】Guards In The Storehouse 題意:一個n*m的房間,每個格子要麽是障礙要麽是空地。對於每個空地你可以選擇放或者不放守衛。一個守衛能保護到的

C#C# in deep 筆記

tar 靜態類型 命名 htable 空類 blank 類型 img net 1. delegate and events http://csharpindepth.com/Articles/Chapter2/Events.aspx 2. 顯式類型 和 隱式類型 3. 靜

C#C# in deep 擴展方法

.text void 靜態方法 com play ext ebr rsize ref C#3 引入的擴展方法這一個理念. 擴展方法最明顯的特征是在方法參數中第一個參數有this聲明. 其實C#庫中有很多已經是擴展方法了.比如linq中對序列使用的查詢語句, where, s

C#C# in deep NullAble<T>

bool 缺點 技術分享 例如 是否 ble 類型 mage 程序 在實際編寫代碼時候 , 會遇到很多場景, 需要將值置成空, 比如發貨日期, 有可能是沒有. 在沒有可空類型之前, 程序都是用 魔值, 即為一個minValue或者常量, 來代表這個值為空, 也有用一個bo

C#C# in deep 泛型

目的 似的 exc string類型 能夠 出現 pub 檢查 代碼塊 泛型 為什麽要有泛型, 在沒有泛型之前, 什麽東西充當了泛型的作用? 在泛型出現之前, 代碼中會有很多需要強制轉換的地方. 比如 int a = (int) object, 對於這樣類似的代碼, 編譯器

PAT 1014 Waiting in Line

urn tell style tel choose malle serve -html ensure Suppose a bank has N windows open for service. There is a yellow line in front of the

CF1015APoints in Segments(簽到)

class include pri getchar() main ret std efi sign 題意:有一條上面有n個點的數軸,給定m次操作,每次覆蓋(x[i],y[i]),求最後沒有被覆蓋過的點的數量與他們的編號 n,m<=100 思路: 1 #includ

JavaException in thread "main" java.lang.UnsupportedClassVersionError

【問題描述】         在Linux上執行jar包出現瞭如下錯誤: 【問題原因】         這個異常是因為較高版本的jdk編譯的java class檔案試圖在較低版本的環境中執行造成的。