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
#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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1017. Queueing at Bank (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- PAT甲题题解-1017. Queueing at Bank (25)-模拟
有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
随机推荐
- Oracle 基础 游标
一:游标的基本原理 游标用来处理从数据库中检索的多行记录(使用SELECT语句).利用游标,程序可以逐个地处理和遍历一次检索返回的整个记录集. 为了处理SQL语句,Oracle将在内存中分配一个区域, ...
- 何为 ISAPI
ISAPI即为Internet Server Application Programming Interface ISAPI 服务器扩展 ISAPI 服务器扩展是可以被 HTTP 服务器加载和调用的 ...
- 用c#写一个json的万能解析器
CommonJsonModel .cs /// <summary> /// 万能JSON解析器 /// </summary> public class CommonJsonMo ...
- node.js安装方法总结
为了保持一致,这里也列举三个方法 第一个方法:通过官网下载安装 https://nodejs.org/en/download/ 这种方式的问题是我们需要自己去找网页,找到链接,然后下载 第二个方法:使 ...
- EIGR的非等价均衡P
DUAL算法(离散更新算法或扩散更新算法) 配置 1.首先配置R1的IP R1(config)#inter f0/0 R1(config-if)#ip address 200.1.1.1 255.25 ...
- C# WinForm动态调用远程Web服务
本文转自:http://blog.csdn.net/muyangjun/article/details/7930871 1.添加服务引用 2.在弹出的添加服务引用对话框地址栏中输入WebService ...
- JSLint notepad++使用
1.JSLint简介 JSLint定义了一组编码约定,这比ECMA定义的语言更为严格.这些编码约定汲取了多年来的丰富编码经验,并以一条年代久远的编程原则 作为宗旨:能做并不意味着应该做.JSLint会 ...
- HTML5/jQuery动画应用 3D视觉效果
今天我们要来分享几款很酷的HTML5/CSS3动画应用,虽然不是HTML5 3D应用,但也有3D的视觉效果.HTML5结合jQuery,让网页应用变得更加强大了.一起来看看这些HTML5/jQuery ...
- 【学习】Windows PE文件学习(一:导出表)
今天做了一个读取PE文件导出表的小程序,用来学习. 参考了<Windows PE权威指南>一书. 首先, PE文件的全称是Portable Executable,可移植的可执行的文件,常见 ...
- .NET4.5可以给所有线程设置默认的Culture了
How to set CurrentCulture for all threads in a domain in .NET 4.5 Before .NET 4.5 if we wanted to se ...