1014. Waiting in Line (30)

布满荆棘的人生 2022-05-31 08:29 255阅读 0赞

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

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

Sample Output

  1. 08:07
  2. 08:06
  3. 08:10
  4. 17:00
  5. Sorry

题目大意:

假设一个银行有N个服务窗口。窗口前有一条黄线,把等候区分为两个部分。客户排队的规则如下:
每个窗口黄线内可以容纳M个用户。因此,当N行都排满后,所有剩下的用户包括第N*M+1个都需要在黄线外排队等待。
每名顾客在穿越黄线时都会先择最短的排队等候。如果有两条或多条相同的长度的线,客户总是选择窗口号最小的那个窗口。
顾客i将用T[i]分钟来处理他的交易。
N个顾客中的第一批假定在早晨8:00服务。
现在给定每个客户的处理时间,你应该计算出客户业务办理完成时的确切时间。
例如:假如一个银行有两个窗口,每个窗口黄线以内可以容纳两名客户。有5名客户在排队等待服务,需要服务的时间分别为1,2,6,4,3分钟。早上8点,客户1在第一个窗口办理业务,同时客户2在第二个窗口办理业务。客户3在第一个窗口前排队客户4在第二个窗口前排队。客户5在黄线之外等待。
在08:01时,客户1办理完业务客户5进入窗口1排队,因为窗口1排的队最短。客户2在08:02离开,客户4在08:06离开,客户3在08:07离开,客户5最后在08:10时离开。
输入:
每一个输入文件包含一个测试用例。每个案例包含4个正整数:N(<=20,代表窗口的数量),M(<=10,代表黄线以内的最大容量),K(<=1000,代表客户的数量),Q(<=1000,代表客户的查询数)。
下一行包含K个正整数,代表K个客户的业务办理时间。
最后一行包括Q个正整数,代表客户业务办理的完成时间。顾客的序号从1到K。
输出:
对于Q个客户中的每一个客户,打印出他/她的办理业务的完成时间,格式为:HH:MM,HH从08到17,MM从00到59.注意因为银行每天17:00关门,对于那些在17:00之后请求服务的客户,你应该输出“Sorry”。

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. queue<int> c[21];
  4. int Customer[1001],T[1001],Time[1001];
  5. int main()
  6. {
  7. int i,j,n,m,k,q,Min,index,num=0;
  8. scanf("%d %d %d %d",&n,&m,&k,&q);
  9. for(i=1;i<=k;i++)
  10. {
  11. scanf("%d",&T[i]);
  12. Time[i]=T[i];
  13. }
  14. for(i=1;i<=q;i++)
  15. {
  16. scanf("%d",&Customer[i]);
  17. }
  18. for(i=1;i<=m*n&&i<=k;)
  19. {
  20. for(j=0;j<n;j++)
  21. {
  22. c[j].push(i++);
  23. }
  24. }
  25. for(;i<=k;i++)
  26. {
  27. Min=T[c[0].front()];
  28. index=0;
  29. for(j=1;j<n;j++)
  30. {
  31. if(Min>T[c[j].front()])
  32. {
  33. Min=T[c[j].front()];
  34. index=j;
  35. }
  36. }
  37. c[index].pop();
  38. c[index].push(i);
  39. if(!c[index].empty())
  40. {
  41. T[c[index].front()]+=Min;
  42. }
  43. }
  44. for(i=0;i<n;i++)
  45. {
  46. while(!c[i].empty())
  47. {
  48. Min=T[c[i].front()];
  49. c[i].pop();
  50. if(!c[i].empty())
  51. T[c[i].front()]+=Min;
  52. }
  53. }
  54. for(i=1;i<=q;i++)
  55. {
  56. if(T[Customer[i]]-Time[Customer[i]]>=540)
  57. {
  58. printf("Sorry\n");
  59. }
  60. else
  61. {
  62. printf("%02d:%02d\n",(T[Customer[i]]+480)/60,(T[Customer[i]]+480)%60);
  63. }
  64. }
  65. return 0;
  66. }

发表评论

表情:
评论列表 (有 0 条评论,255人围观)

还没有评论,来说两句吧...

相关阅读

    相关 BNUOJ 52511 Keep In Line

    队列,$map$。 每次出队进行出队操作的是时候,先把队列中需要出队的人全部出队,然后比较对头和当前出队的人是否相同。 #include<bits/stdc++.h>...