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:

  1. 7 3
  2. 07:55:00 16
  3. 17:00:01 2
  4. 07:59:59 15
  5. 08:01:00 60
  6. 08:00:00 30
  7. 08:00:02 2
  8. 08:03:00 10

Sample Output:

  1. 8.2
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<math.h>
  5. using namespace std;
  6. typedef struct{
  7. int come;
  8. int process;
  9. }info;
  10. info people[];
  11. int window[];
  12. int N, K;
  13. bool cmp(info a, info b){
  14. return a.come < b.come;
  15. }
  16. int main(){
  17. int hh, mm, ss, len;
  18. scanf("%d%d", &N, &K);
  19. for(int i = ; i < N; i++){
  20. scanf("%d:%d:%d %d", &hh, &mm, &ss, &len);
  21. people[i].come = hh * + mm * + ss;
  22. people[i].process = len * ;
  23. }
  24. sort(people, people + N, cmp);
  25. int wait = , early = * , late = * ;
  26. fill(window, window + K, early);
  27. int cnt = ;
  28. for(int i = ; i < N; i++){
  29. int index = -, minT = ;
  30. for(int j = ; j < K; j++){
  31. if(window[j] < minT){
  32. minT = window[j];
  33. index = j;
  34. }
  35. }
  36. if(people[i].come > late)
  37. break;
  38. cnt++;
  39. if(people[i].come >= window[index]){
  40. window[index] = people[i].process + people[i].come;
  41. }else{
  42. wait += (window[index] - people[i].come);
  43. window[index] += people[i].process;
  44. }
  45. }
  46. double AVG = (double)wait / (double)(cnt * );
  47. printf("%.1f", AVG);
  48. cin >> N;
  49. return ;
  50. }

总结:

1、模拟排队和服务的问题。不要把window数组仅仅设置为占用和不占用,而是用windows[ i ]记录该窗口可被使用的时间。初始化时都被置为8:00,即8点之后才可服务。

2、由于题目给出的顾客是乱的,先按时间排序。一次处理每一个顾客,对每一个顾客,选择一个可被使用的时间最早的窗口对其处理,如果顾客来的时间早于窗口可服务时间,则等待时间累加,并修改窗口可服务时间;如果晚于,则可立即服务没有等待时间,但依旧修改窗口可服务时间。如果顾客晚于17点或最早可被使用的窗口晚于17点则无法服务。

3、为了便于计算,所有时间换算成秒。没有被服务的顾客不计入等待时间。

A1017. Queueing at Bank的更多相关文章

  1. PAT A1017 Queueing at Bank (25 分)——队列

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...

  2. PAT甲级——A1017 Queueing at Bank

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...

  3. [PAT] A1017 Queueing at Bank

    [思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...

  4. PAT1017:Queueing at Bank

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  5. PAT 1017 Queueing at Bank[一般]

    1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...

  6. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  7. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  8. pat1017. Queueing at Bank (25)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  9. PAT 甲级 1017 Queueing at Bank (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)

    1017 Queueing at Bank (25 分)   Suppose a bank has K windows open for service. There is a yellow line ...

随机推荐

  1. PMP三点

    三点估算:悲观36天,可能21天,乐观6天.在16至26天内完成的概率是多少?这个算法是PERT估算最终估算结果=(悲观工期+乐观工期+4×最可能工期)/6=(36+6++4*21)/6=21标准差= ...

  2. python爬虫之线程池和进程池

    一.需求 最近准备爬取某电商网站的数据,先不考虑代理.分布式,先说效率问题(当然你要是请求的太快就会被封掉,亲测,400个请求过去,服务器直接拒绝连接,心碎),步入正题.一般情况下小白的我们第一个想到 ...

  3. Navicat Preminum

    此软件在连接的时候,需要这样: 新建链接==>连接属性==>编码选择自动==>如果此时点击确定的话,会把整个服务器的所有数据库都打开, 我们也可以只打开指定的数据库, 点击高级==& ...

  4. linux 挂载windows下目录,其它linux机器nfs的目录,自己dd的文件

    如有转载,不胜荣幸.http://www.cnblogs.com/aaron-agu/ 挂载window下共享的目录 //192.168.0.11/share /mnt 挂载其它linux机器下目录 ...

  5. Learning to Rank(转)

    https://blog.csdn.net/kunlong0909/article/details/16805889 Table of Contents 1 前言 2 LTR流程 3 训练数据的获取4 ...

  6. 在线制作css动画——CSS animate

    熟悉CSS的人都知道,CSS可以实现很多漂亮的动画,特别是它的在线功能,能够帮助人们解决很多制作动画的效果.今天特别推荐一个在线CSS插件功能——cssanimate,这个最大的特色就是以图形界面方式 ...

  7. 洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

    题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...

  8. no module named 'win32api'问题

    运行scrapy时,报错no module named 'win32api' 解决办法: https://github.com/mhammond/pywin32/releases 下载对于python ...

  9. Spring 使用介绍(三)—— 资源

    一.Resource接口 Spring提供Resource接口,代表底层外部资源,提供对底层外部资源的一致性访问接口 public interface InputStreamSource { Inpu ...

  10. Matplotlib学习---matplotlib里颜色,标记,线条类型参数的选择(colors, markers, line styles)

    颜色(Colors): 基础颜色: character color 'b' blue 'g' green 'r' red 'c' cyan 'm' magenta 'y' yellow 'k' bla ...