http://www.patest.cn/contests/pat-a-practise/1014
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:
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 Input2 2 7 5 1 2 6 4 3 534 2 3 4 5 6 7Sample Output
08:07 08:06 08:10 17:00 Sorry坑点:
1.总人数可能比窗口能容纳的人数要少
2.those customers who cannot be served before 17:00,审题不仔细
#include <stdio.h> #include <queue> #define MAXW 20 #define MAXM 10 #define MAXK 1001 using namespace std; typedef struct{ int id; int t; }CUS; queue<CUS> w[MAXW]; queue<CUS> q; int ftime[MAXK];//完成时间 int ctime[MAXK];//每个人需要被服务的时间 int quiry[MAXK];//哪些人在问 int main(){ int i,j,W,M,K,Q,l,hh,mm,cnt; CUS t; CUS *tmp; scanf("%d%d%d%d",&W,&M,&K,&Q); l = W * M; if(K > l){//总人数多于窗口能容纳的人数时 for(i = 1;i <= l;i++){ scanf("%d",&t.t); t.id = i; w[(i-1)%W].push(t); ctime[t.id] = t.t; } for(;i <= K;i++){ scanf("%d",&t.t); t.id = i; q.push(t); ctime[t.id] = t.t; } } else{//。。。。 for(i = 1;i <= K;i++){ scanf("%d",&t.t); t.id = i; w[(i-1)%W].push(t); ctime[t.id] = t.t; } } //每次循环减少非空队队首那个人所需要的处理时间,减到0时就认为是被服务完 //从而移除队列。此时,如果黄线外还有人在排队,就入队到刚才移出了人的那个队列 for(i = 1,cnt = 0;cnt < K;i++){ for(j = 0;j < W;j++){ if(w[j].empty()) continue; tmp = &w[j].front(); tmp->t--; if(tmp->t == 0){ cnt++; ftime[tmp->id] = i; w[j].pop(); if(!q.empty()){ w[j].push(q.front()); q.pop(); } } } } for(i = 0;i < Q;i++){ scanf("%d",&quiry[i]); } //从一个人被服务完的时间往回算,如果算到的完成时间在17:00或者17:00以后,都是sorry。 //note:包括17:00点才开始被serve的,也要sorry.服务完成时间大于17:00,但是开始服务的时间在17:00之前的是可以的 for(i = 0;i < Q;i++){ if(ftime[quiry[i]]-ctime[quiry[i]] >= 540){ printf("Sorry\n"); continue; } hh = 8 + ftime[quiry[i]] / 60; mm = ftime[quiry[i]] % 60; printf("%02d:%02d\n",hh,mm); } return 0; }