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、为了便于计算,所有时间换算成秒。没有被服务的顾客不计入等待时间。

A1017. Queueing at Bank的更多相关文章

  1. PAT A1017 Queueing at Bank (25 分)——队列

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

  2. PAT甲级——A1017 Queueing at Bank

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

  3. [PAT] A1017 Queueing at Bank

    [思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...

  4. PAT1017:Queueing at Bank

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  5. PAT 1017 Queueing at Bank[一般]

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

  6. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  7. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  8. pat1017. Queueing at Bank (25)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

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

随机推荐

  1. 源码追踪,解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.问题

    在windows系统本地运行spark的wordcount程序,会出现一个异常,但不影响现有程序运行. >>提君博客原创  http://www.cnblogs.com/tijun/  & ...

  2. Windows环境下在IDEA编辑器中spark开发安装步骤

    以下是windows环境下安装spark的过程: 1.安装JDK(version:1.8.0.152) 2.安装scala(version:2.11/2.12) 3.安装spark(version:s ...

  3. Could not render e, see the console.

    错误截图: 解决: 在application.properties中开启swagger swagger2.enable=true

  4. vhdl——type

    TYPE 数据类型名 IS 数据类型定义 OF 基本数据类型 TYPE 数据类型名 IS 数据类型定义 常用的用户自定义的数据类型有枚举型,数组型,记录型.其中枚举型的在状态机的描述中经常使用到 ,数 ...

  5. 【CPU】理解CPU

    CPU,全称Central Processing Unit,即中央处理器. 何为CPU? 计算机必须能够自动地从主存中取出一条条指令执行,专门来执行指令的就是CPU. 一.指令的执行过程 为了理解CP ...

  6. Qt 网格布局

    把十六个button放到网格布局的界面上 #include "mainwindow.h" #include <QApplication> #include<QtW ...

  7. [51Nod 1584] 加权约数和

    Description 在整理以前的试题时,他发现了这样一道题目:"求 \(\sum\sigma(i)\),其中 \(1≤i≤N\),\(σ(i)\) 表示 \(i\) 的约数之和.&quo ...

  8. BZOJ4128Matrix——hash+矩阵乘法+BSGS

    题目描述 给定矩阵A,B和模数p,求最小的x满足 A^x = B (mod p) 输入 第一行两个整数n和p,表示矩阵的阶和模数,接下来一个n * n的矩阵A.接下来一个n * n的矩阵B 输出 输出 ...

  9. UOJ356 [JOI2017春季合宿] Port Facility 【启发式合并】【堆】【并查集】

    题目分析: 好像跑得很快,似乎我是第一个启发式合并的. 把玩具看成区间.首先很显然如果有两个玩具的进出时间有$l1<l2<r1<r2$的关系,那么这两个玩具一定在不同的栈中间. 现在 ...

  10. 学习Android过程中遇到的问题及解决方法——网络请求

    在学习Android的网络连接时遇到崩溃或异常(出现的问题就这两个,但是不稳定)的问题,先上代码,看看哪里错了(答案在文末) activity_main.xml: <?xml version=& ...