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<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
struct cus
{
int arrive_time,cost;
};
struct win
{
win():win_time(**){}
int win_time;
}; win wins[]; bool cmparrive(cus a,cus b)
{
return a.arrive_time < b.arrive_time;
}
int main()
{
int n,w_num,hh,mm,ss;
cus ctem;
vector<cus> vv;
scanf("%d%d",&n,&w_num);
for(int i = ;i < n;++i)
{
scanf("%d:%d:%d%d",&hh,&mm,&ss,&ctem.cost);
if(ctem.cost > )
ctem.cost = ;
ctem.cost *= ;
ctem.arrive_time = hh** + mm* + ss;
if(ctem.arrive_time <= * * )
vv.push_back(ctem);
}
sort(vv.begin(),vv.end(),cmparrive);
int cnt = ;
double sum = 0.0;
n = vv.size();
while(cnt < n)
{
int MIN = ;
int MINindex = -;
for(int i = ;i < w_num;++i)
{
if(MIN > wins[i].win_time)
{
MIN = wins[i].win_time;
MINindex = i;
}
}
if(MIN > vv[cnt].arrive_time)
{
sum += (MIN - vv[cnt].arrive_time);
wins[MINindex].win_time += vv[cnt].cost;
++cnt;
}
else
{
for(int i = ;i < w_num;++i)
{
if(vv[cnt].arrive_time >= wins[i].win_time)
{
MINindex = i;
break;
}
}
wins[MINindex].win_time = vv[cnt].arrive_time + vv[cnt].cost;
++ cnt;
}
}
if(n == )
printf("0.0\n");
else
printf("%.1lf\n",sum/60.0/n);
return ;
}
												

1017. Queueing at Bank (25)的更多相关文章

  1. 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 ...

  2. 1017. Queueing at Bank (25) - priority_queuet

    题目如下: Suppose a bank has K windows open for service. There is a yellow line in front of the windows ...

  3. 1017 Queueing at Bank (25)(25 point(s))

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

  4. PAT 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 ...

  5. 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 ...

  6. PAT (Advanced Level) 1017. Queueing at Bank (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  7. PAT甲题题解-1017. Queueing at Bank (25)-模拟

    有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...

  8. 【PAT甲级】1017 Queueing at Bank (25 分)

    题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...

  9. PAT 1017 Queueing at Bank[一般]

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

随机推荐

  1. 【Linux】gdb调试core文件

    编写服务器端程序,很容易遇到Crash问题,比较幸运的是Linux提供了core file,保留了Crash的现场.有时候,根据当前的调用栈,并且打印出当前栈的变量就可以分析出crash的原因,但是, ...

  2. page74-泛型可迭代的基础集合数据类型的API-Bag+Queue+Stack

    [泛型可迭代的基础集合数据类型的API] 背包:就是一种不支持从中删除元素的集合数据类型——它的目的就是帮助用例收集元素并迭代遍历所有收集到的元素.(用例也可以检查背包是否为空, 或者获取背包中元素的 ...

  3. Shell学习笔记 - 正则表达式

    一.正则表达式是什么? 正则表达式是用于描述字符排列和匹配模式的一种语法规则.它主要用于字符串的模式分割.匹配.查找及替换操作. 二.正则表达式与通配符 1. 正则表达式 用来在文件中匹配符合条件的字 ...

  4. Matlab的GUI参数传递方式总结

    MATLAB GUI传递方式 1.全局变量: 2.作为函数的参数传递: 3.利用控件的userdata数据: 4.为handles结构体添加新字段: 5.setappdata函数为句柄添加数据: 6. ...

  5. backbone.Router History源码笔记

    Backbone.History和Backbone.Router history和router都是控制路由的,做一个单页应用,要控制前进后退,就可以用到他们了. History类用于监听URL的变化, ...

  6. 前端插件Emmet

    Sublime text安装 步骤一:首先你需要为sublime text安装Package Control组件: 按Ctrl+`调出sublime text的console 粘贴以下代码到底部命令行 ...

  7. WinFrom“动态”WebService

    1.首先添加一个WebService: 2.输入地址....Ok: 3.在WebService用到的类上按F12: 4.进入类中,找到其构造函数: 5.修改其构造函数为代参数,并且让this.Url= ...

  8. HDU1358:Period

    第一次做KMP.还没有理解透. 在自己写一遍时没有让next[0]初始化为-1. 还有就是next应该是c++中的关键字,提交后编译错误. From: http://blog.csdn.net/lib ...

  9. DWZ (JUI) 教程 tree 控件的选中事件

    DWZ (JUI) 教程 tree 控件的选中事件 先简单说一下流程 第一步 当然是先定义好回调事件了 function checkCallback(json){ ........... ...... ...

  10. shell命令getopts解析

    getopts是一条获取和处理命令行选项的语句,格式为getopts option_string variable .其中option_string中包含一个有效的单字符选项,若getopts命令在命 ...