1014 Waiting in Line (30 分) PTA甲級(jí)

題目鏈接

題目描述

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;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市攀唯,隨后出現(xiàn)的幾起案子洁桌,更是在濱河造成了極大的恐慌,老刑警劉巖侯嘀,帶你破解...
    沈念sama閱讀 217,406評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件另凌,死亡現(xiàn)場離奇詭異,居然都是意外死亡戒幔,警方通過查閱死者的電腦和手機(jī)吠谢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來诗茎,“玉大人工坊,你說我怎么就攤上這事。” “怎么了王污?”我有些...
    開封第一講書人閱讀 163,711評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵罢吃,是天一觀的道長。 經(jīng)常有香客問我玉掸,道長刃麸,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,380評(píng)論 1 293
  • 正文 為了忘掉前任司浪,我火速辦了婚禮泊业,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘啊易。我一直安慰自己吁伺,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評(píng)論 6 392
  • 文/花漫 我一把揭開白布租谈。 她就那樣靜靜地躺著篮奄,像睡著了一般。 火紅的嫁衣襯著肌膚如雪割去。 梳的紋絲不亂的頭發(fā)上窟却,一...
    開封第一講書人閱讀 51,301評(píng)論 1 301
  • 那天,我揣著相機(jī)與錄音呻逆,去河邊找鬼夸赫。 笑死,一個(gè)胖子當(dāng)著我的面吹牛咖城,可吹牛的內(nèi)容都是我干的茬腿。 我是一名探鬼主播,決...
    沈念sama閱讀 40,145評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼宜雀,長吁一口氣:“原來是場噩夢啊……” “哼切平!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起辐董,我...
    開封第一講書人閱讀 39,008評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤悴品,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后简烘,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體他匪,經(jīng)...
    沈念sama閱讀 45,443評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評(píng)論 3 334
  • 正文 我和宋清朗相戀三年夸研,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了邦蜜。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,795評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡亥至,死狀恐怖悼沈,靈堂內(nèi)的尸體忽然破棺而出贱迟,到底是詐尸還是另有隱情,我是刑警寧澤絮供,帶...
    沈念sama閱讀 35,501評(píng)論 5 345
  • 正文 年R本政府宣布衣吠,位于F島的核電站,受9級(jí)特大地震影響壤靶,放射性物質(zhì)發(fā)生泄漏缚俏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評(píng)論 3 328
  • 文/蒙蒙 一贮乳、第九天 我趴在偏房一處隱蔽的房頂上張望忧换。 院中可真熱鬧,春花似錦向拆、人聲如沸亚茬。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽刹缝。三九已至,卻和暖如春颈将,著一層夾襖步出監(jiān)牢的瞬間梢夯,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評(píng)論 1 269
  • 我被黑心中介騙來泰國打工晴圾, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留颂砸,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,899評(píng)論 2 370
  • 正文 我出身青樓疑务,卻偏偏與公主長得像,于是被迫代替她去往敵國和親梗醇。 傳聞我的和親對(duì)象是個(gè)殘疾皇子知允,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容