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 ...
随机推荐
- 深入理解HTTPS通讯原理
一.HTTPS简介 HTTPS(Hyper Text Transfer Protocol over Secure Socket Layer),简单来讲就是加了安全的HTTP,即HTTP+SSL:我们知 ...
- DWZ按钮居中显示
- 剑指Offer01 杨氏数组寻值
/************************************************************************* > File Name: 001.c > ...
- hdu-5587 Array(回溯)
题目链接: Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) P ...
- C之文件读写
1.fopen() fopen的原型是:FILE *fopen(const char *filename,const char *mode),fopen实现三个功能:为使用而打开一个流,把一个文件和此 ...
- 转载事务在C#方法里的应用
问题:一个系统的数据库更新或者插入的时候若遭遇到断电等能引起数据库不能正常工作的情况的话,其更新或插入的将是不完整的数据,或者是错误的数据.故需要引入事务处理. 实例:数据更新的事务处理. 解决方案: ...
- Android studio 安装和使用
之前一直是使用eclipse+ADT+SDK进行Android的开发的,不愿意转到Android studio是因为熟悉了eclipse的开发环境,最近偶然使用了android studio,感觉比使 ...
- 解决 Oracle em 无法打开的问题
重建em emca -deconfig dbcontrol db -repos drop 删除 emca -config dbcontrol db -repos create 创建 set ora ...
- 未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“xxx.Resources.resources”正确嵌入或链接到程序集
今天在测试一个工程的时候,突然遇到了这样一个问题: 错误信息:System.Resources.MissingManifestResourceException: 未能找到任何适合于指定的区域或非特定 ...
- UIAlertView[警告框] [代理协议型]UIActionSheet [表单视图][代理协议型]
//// ViewController.h// UIAlertViewAndUIActionSheet//// Created by hehe on 15/9/21.// Copyright ...