題目描述
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
題意理解
n個(gè)窗口吕朵,每個(gè)窗口可以排隊(duì)m人循帐。有k位用戶需要服務(wù),給出了每位用戶需要的minute數(shù)昨忆,所有客戶在8點(diǎn)開始服務(wù),如果有窗口還沒排滿就入隊(duì),否則就在黃線外等候。如果有某一列有一個(gè)用戶走了服務(wù)完畢了拯坟,黃線外的人就進(jìn)來一個(gè)。如果同時(shí)就選窗口數(shù)小的韭山。求q個(gè)人的服務(wù)結(jié)束時(shí)間似谁。
如果一個(gè)客戶在17:00以及以后還沒有開始服務(wù)(此處不是結(jié)束服務(wù)是開始17:00)就不再服務(wù)輸出sorry;如果這個(gè)服務(wù)已經(jīng)開始了掠哥,無論時(shí)間多長都要等他服務(wù)完畢。
————————————————
摘自CSDN博主「柳婼」的原創(chuàng)文章
原文鏈接:https://blog.csdn.net/liuchuo/article/details/54561626
測試點(diǎn)分析
在測試點(diǎn)4卡了一會(huì)秃诵,測試點(diǎn)4是在黃線內(nèi)的人被sorry的情況
AC代碼
#include<bits/stdc++.h>
using namespace std;
int main(){
int win_num, win_len, n, k;
scanf("%d %d %d %d", &win_num, &win_len, &n, &k);
vector<vector<int>> times(win_num); //times按順序記錄每個(gè)窗口中排隊(duì)的人的結(jié)束時(shí)間续搀,用以標(biāo)示下一個(gè)進(jìn)入的人的開始時(shí)間
vector<int> data(n), start_time(n); //data記錄每個(gè)用戶的耗時(shí),start_time記錄每個(gè)用戶的開始時(shí)間
for(int i=0; i<n; i++) scanf("%d", &data[i]);
for(int i=0; i<n&&i<win_num*win_len; i++){ //先把黃線內(nèi)的人排隊(duì)排好
int t = i%win_num; //第t個(gè)窗口
start_time[i] = i<win_num?0:times[t][i/win_num-1]; //第一排的開始時(shí)間是0菠净,之后的開始時(shí)間是前一排的結(jié)束時(shí)間禁舷,從times中獲取
times[t].push_back(start_time[i]+data[i]);
}
for(int i=win_num*win_len; i<n; i++){ //黃線外的人進(jìn)入隊(duì)伍
int mint=540, w=-1;
for(int j=0; j<win_num; j++){ //選擇隊(duì)伍,按隊(duì)伍中size()-win_len個(gè)人的最早開始時(shí)間選擇
int st = times[j][times[j].size()-win_len];
if(st<mint){
mint = st;
w = j;
}
}
if(w==-1) start_time[i] = 540; //沒窗口選毅往,全都已經(jīng)超時(shí)牵咙,按540計(jì)
else{
start_time[i] = times[w][times[w].size()-1]; //計(jì)算開始時(shí)間
times[w].push_back(start_time[i]+data[i]); //排隊(duì)進(jìn)入
}
}
for(int i=0; i<k; i++){
int x;
scanf("%d", &x);
x--;
if(start_time[x]>=540) printf("Sorry\n");
else printf("%02d:%02d\n", (start_time[x]+data[x])/60+8, (start_time[x]+data[x])%60);
}
return 0;
}