zoukankan      html  css  js  c++  java
  • PAT甲级——A1014 Waiting in Line

    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 (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.
    • Customeri​​ will take Ti​​ 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 Specification:

    Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (≤, number of windows), M (≤, the maximum capacity of each line inside the yellow line), K (≤, number of customers), and Q (≤, number of customer queries).

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

    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 Specification:

    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个窗口,每个窗口线内排队M个人,其他人在线外等候
    哪个窗口有空缺,那么就上那个窗口去排队
    当有多个窗口空缺,则选择小号排队
    问每个人从早上8.00到他办完业务的具体时间


    有个点得注意一下,就是当有个人排队在16:59开始办业务,
    就算他要办1000分钟的业务,他也是算能办上业务的,不应输出sorry

     1 #include<iostream>
     2 #include <vector>
     3 #include <queue>
     4 using namespace std;
     5 
     6 
     7 int N, M, K, Q;
     8 
     9 int main()
    10 {
    11     cin >> N >> M >> K >> Q;
    12     vector<queue<int>>windows(N);//N个窗口
    13     vector<int>endTime(K + 1);
    14     vector<bool>Sorry(K + 1, false);//若前面那个人的业务办理时间超过下班时间,那么你是排不上的
    15     int a, time;
    16     for (int i = 0; i < K; ++i)
    17     {
    18         cin >> a;
    19         if (i < N * M)//先将窗口的位子按序排满,存的是该人完成业务的时间
    20         {
    21             if (windows[i%N].size() > 0)
    22             {
    23                 time = windows[i%N].back() + a;
    24                 windows[i%N].push(time);
    25                 Sorry[i + 1] = windows[i%N].back() >= 540 ? true : false;
    26             }
    27             else
    28             {
    29                 time = a;
    30                 windows[i%N].push(a);                
    31             }
    32         }
    33         else//线外的人选择窗口排队
    34         {
    35             int minTime = windows[0].front(), index = 0;
    36             for (int j = 1; j < N; ++j)//找到最先出现空位的窗口,然后去选择该窗口排队
    37             {
    38                 if (minTime > windows[j].front())
    39                 {
    40                     index = j;
    41                     minTime = windows[j].front();
    42                 }
    43             }
    44             Sorry[i + 1] = windows[index].back() >= 540 ? true : false;
    45             time = windows[index].back() + a;
    46             windows[index].pop();//排完对队就离开
    47             windows[index].push(time);//排队
    48         }
    49         endTime[i + 1] = time;
    50     }
    51 
    52     for (int i = 0; i < Q; ++i)
    53     {
    54         cin >> a;
    55         time = endTime[a];
    56         if (Sorry[a])
    57             printf("Sorry
    ");
    58         else
    59             printf("%02d:%02d
    ", 8 + time / 60, time % 60);
    60     }
    61     return 0;
    62 }
     
  • 相关阅读:
    spring 环绕通知 ProceedingJoinPoint 执行proceed方法的作用是什么
    SpringMVC之RequestContextHolder分析
    MySQL中索引不会被用到的情况
    使用Stream快速对List进行一些操作
    Vue中this.$refs[name].resetFields();的使用
    好看的字体
    转,javascript中call()、apply()、bind()的用法终于理解
    vue中的$props
    手机端页面自适应解决方案-rem布局
    查看项目里特定npm包的版本号
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11191808.html
Copyright © 2011-2022 走看看