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. 《Cortex-M0权威指南》之体系结构---栈空间操作

    转载请注明来源:cuixiaolei的技术博客 栈空间作为一种存储器使用机制,是"先入先出"的结构,在系统空间中用作临时数据的存储.栈空间操作的关键之一为栈指针寄存器,每次执行栈操 ...

  2. VS2013 支持python和nodejs

    一.在VS2013中,安装python的支持 1. http://pytools.codeplex.com/下载插件 2. https://www.python.org/download/下载Pyth ...

  3. C++ 中的virtual关键词

    C++ 中的virtual关键词 动态绑定 所谓动态绑定,我的理解就是一个函数在调用之前无法得知参数的具体类型(基类还是派生类).C++ Primer上描述了两种动态绑定的情况: 要触发动态绑定,必须 ...

  4. Oracle language types(语言种类) 表的相关操作 DDL数据定义语言

    数据定义语言 Data Definition Language Statements(DDL)数据操纵语言 Data Manipulation Language(DML) Statements事务控制 ...

  5. HTTPS的工作原理

    参考自<图解HTTP> 果壳网http://www.guokr.com/post/114121/ HTTPS的工作原理 增加了一层:HTTPS流程:应用层 HTTP->SSL/TLS ...

  6. 清除层div浮动

    clearboth { clear: both; display: block; height: 0; font-size: 0; overflow: hidden; } <div class= ...

  7. HDU 4422 The Little Girl who Picks Mushrooms ( 模拟)

    Problem Description It's yet another festival season in Gensokyo. Little girl Alice planned to pick ...

  8. Incorporating ASP.NET MVC and SQL Server Reporting Services, Part 1

    Your ASP.NET MVC application needs reports. What do you do? In this article, I will demonstrate how ...

  9. Java之经典Student问题2

    创建5个学生对象给一个学生数组赋值,每个学生属性有:学号.姓名.年龄. 要求:1.给每个学生排序输出.  2.给所有学生年龄加1.  3.统计年龄大于20的学生人数. 在这里,我们用了compareT ...

  10. FusionCharts 相关知识

    FusionCharts1.平均线: <trendLines><line startValue='{0}' toolText='平均线' color='#FF0000' displa ...