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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef struct{
int come;
int process;
}info;
info people[];
int window[];
int N, K;
bool cmp(info a, info b){
return a.come < b.come;
}
int main(){
int hh, mm, ss, len;
scanf("%d%d", &N, &K);
for(int i = ; i < N; i++){
scanf("%d:%d:%d %d", &hh, &mm, &ss, &len);
people[i].come = hh * + mm * + ss;
people[i].process = len * ;
}
sort(people, people + N, cmp);
int wait = , early = * , late = * ;
fill(window, window + K, early);
int cnt = ;
for(int i = ; i < N; i++){
int index = -, minT = ;
for(int j = ; j < K; j++){
if(window[j] < minT){
minT = window[j];
index = j;
}
}
if(people[i].come > late)
break;
cnt++;
if(people[i].come >= window[index]){
window[index] = people[i].process + people[i].come;
}else{
wait += (window[index] - people[i].come);
window[index] += people[i].process;
}
}
double AVG = (double)wait / (double)(cnt * );
printf("%.1f", AVG);
cin >> N;
return ;
}

总结:

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

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

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

最新文章

  1. 自定义ConfigSection
  2. java接口(二)
  3. Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份
  4. LINQ to Entities 不支持 LINQ 表达式节点类型“Invoke”(笔记)
  5. CentOS 6.5 安装Nginx 1.7.4
  6. 【LeetCode】88 - Merge Sorted Array
  7. C#相关图书推荐
  8. Throwing cards away I
  9. 5、第5节课CSS补充和html 标签讲解20150924
  10. 处理html页面元素工具类(HtmlAgilityPack.dll)的使用
  11. nodejs 全局变量和全局对象
  12. 1.8 range
  13. 【一天一道LeetCode】#80. Remove Duplicates from Sorted Array II
  14. Chromium被用于Microsoft Edge与ChakraCore的未来【译】
  15. 【转】app之YdbOnline说明文档
  16. base64加密和解码原理和代码
  17. 在Centos 6 64bit 上安装 Hyperic HQ 5.8.2.1 中文版
  18. 文章如何做伪原创 SEO大神教你几招做&quot;原创&quot;网站文章的心得
  19. jquery easyui tree异步加载子节点
  20. Linux文件系统性能优化

热门文章

  1. 下拉框插件select2的使用
  2. jQuery操作复选框checkbox技巧总结 ---- 设置选中、取消选中、获取被选中的值、判断是否选中等
  3. [转]Java 的强引用、弱引用、软引用、虚引用
  4. 关于PHP函数传参的注意点
  5. MySQL——基础操作
  6. 在 Web 页面使用 VLC 插件播放 m3u8 视频流 (360 极速模式)
  7. 【python练习题】程序14
  8. How to write to an event log by using Visual C#
  9. 使用Windows任务计划程序运行Windows PowerShell脚本
  10. bzoj2762-[JLOI2011]不等式组