zoukankan      html  css  js  c++  java
  • 1017. Queueing at Bank (25)

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.

    Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.

    Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.

    Output Specification:

    For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.

    Sample Input:

    7 3
    07:55:00 16
    17:00:01 2
    07:59:59 15
    08:01:00 60
    08:00:00 30
    08:00:02 2
    08:03:00 10
    

    Sample Output:

    8.2
    题目大意:有n个客户,k个窗口。已知每个客户的到达时间和需要的时长(不超过60min,超过的会被压缩成60min),
    如果有窗口就依次过去,如果没有窗口就在黄线外等候(黄线外只有一个队伍),求客户的平均等待时长。
    银行开放时间为8点到17点,在8点之前不开门,8点之前来的人都要等待,在17点后来的人不被服务
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 int sum[101];  //每个窗口服务时间
     5 struct node
     6 {
     7     int arrive;  //到达时间
     8     int serve;   //客户需服务时间
     9 }client[10001];
    10 int cmp( const void * a, const void *b)
    11 {
    12     struct node *c = ( struct node *)a;
    13     struct node *d = ( struct node *)b;
    14     return c->arrive - d->arrive;  //到达时间按升序排列
    15 }
    16 int main()
    17 {
    18     int n,k,cnt=0;
    19     int i,j,x;
    20     int h,m,s,p,temp;
    21     int maxtime=0;
    22     scanf("%d%d",&n,&k);
    23     for( i=1; i<=n; i++)
    24     {
    25         scanf("%d:%d:%d %d",&h,&m,&s,&p);
    26         temp = h*3600+m*60+s;
    27         if( temp>61200 )  //如果到达时间超过17点则丢弃
    28             continue;
    29         if( p>60)  //如果服务时间超过60压缩为60
    30             p=60;
    31         client[cnt].arrive = temp;
    32         client[cnt].serve=p*60;
    33         cnt++;  //统计有效人数
    34     }
    35     qsort( client, cnt, sizeof(client[1]),cmp);
    36     for( x=0; x<k; x++)
    37          sum[x]=28800;  //服务时间从8点开始
    38     for( i=0; i<cnt; i++)
    39     {
    40         int minwindow=0, mintime = sum[0];
    41         for( j=1; j<k; j++)  //寻找最先服务完的窗口
    42         {
    43             if( mintime > sum[j])
    44             {
    45                 mintime = sum[j];
    46                 minwindow = j;
    47             }
    48         }
    49         if( sum[minwindow]<=client[i].arrive) //如果客户到来前已经服务完
    50             sum[minwindow] = client[i].arrive+client[i].serve;
    51         else{
    52             maxtime += ( sum[minwindow]-client[i].arrive);
    53             sum[minwindow]+=client[i].serve;
    54         }
    55     }
    56     if( cnt==0)
    57         printf("0.0");
    58     else
    59          printf("%.1f",maxtime/60.0/cnt);  //以分钟计算平均值
    60     return 0;
    61 }
    
    
    在这个国度中,必须不停地奔跑,才能使你保持在原地。如果想要寻求突破,就要以两倍现在速度奔跑!
  • 相关阅读:
    Cannot attach the file *.mdf as database
    frameset frame 实例和用法 转
    remove element
    伸展树--java
    Remove Duplicates from Sorted Array
    merge two sorted lists
    valid parentheses
    Longest Common Prefix
    palindrome number(回文数)
    Two Sum
  • 原文地址:https://www.cnblogs.com/yuxiaoba/p/8565973.html
Copyright © 2011-2022 走看看