1017 Queueing at Bank
题意:银行有K个窗口用于服务,给出所有人的达到时间T和服务时间P,计算所有被服务的客户的平均等待时间。任何客户的服务时间不得超过60分钟。早于08:00到的,要等到08:00;在17:00:01及之后到的,不给予服务,不参与计算平均等待时间。
思路:首先,对所有顾客的到达时间进行排序;其次,令数组windows[i]表示窗口i当前顾客的结束服务的时间,初始化为08:00,这样的话,每次要安排下一个顾客前往某窗口接受服务时,就遍历所有窗口,找出当前最快结束的那个窗口(记为minidx),然后让这位顾客去minidx号窗口接受服务。顾客的等待时间分为两种情况:
1)若顾客到达的时间比较早,早于当前窗口的最早结束的时间,如当前窗口结束前一个人的服务时间是08:16,但是下一位顾客08:01(其服务时间是60分钟)就到了,则该顾客需等待15分钟,而该窗口的最早结束服务的时间就更新为08:16+60min;
2)若顾客到达的时间比较晚,晚于当前窗口的最早结束的时间,如当前窗口结束前一个人的服务时间是08:16,但是下一位顾客08:20(其服务时间是60分钟)才到,则该顾客无需等待,相应的,该窗口的最早结束服务的时间就更新为08:20+60min,注意区别,这种情况下,时间更新为该顾客的到达时间+其服务时长!
一些注意点:
1.为了时间比较的方便,统一化成以秒为单位;
2.因为任何客户的服务时间不得超过60分钟,故在数据输入时就先做好判断,如果某个顾客服务时间超过60分钟的,直接截断成60分钟;
3.因为在17:00:01及之后到的,不给予服务,不参与计算平均等待时间,即无效数据,故在数据输入时就先剔除;
我的主要问题出在了更新状态未考虑周全,即上面所说的情况(2)。
代码:
#include <cstdio>
#include <algorithm>
using namespace std;
*;
*;
//时间均以秒为单位
struct Customer{
int arrivedTime;
int servedTime;
}cus[];
;//总的等待时间
];//表示窗口i的最早结束服务的时间,初始化为START_TIME
bool cmp(Customer a,Customer b){
return a.arrivedTime<b.arrivedTime;
}
int main()
{
//freopen("pat.txt","r",stdin);
fill(windows,windows+,START_TIME);//初始化
;
scanf("%d%d",&n,&k);
int hh,mm,ss,serve;
;i<n;i++){
scanf("%d:%d:%d%d",&hh,&mm,&ss,&serve);
+mm*+ss>END_TIME) continue;//如果到达时间超过下班时间,则无效
cus[validCnt].arrivedTime=hh*+mm*+ss;
cus[validCnt++].servedTime=(serve>?:serve)*;
}
sort(cus,cus+validCnt,cmp);
;
while(idx<validCnt){
//遍历所有窗口,寻找当前哪个窗口最先有空
,minTime=0x7fffffff;
;i<k;i++){
if(windows[i]<minTime){
minTime=windows[i];
minidx=i;
}
} //更新
if(windows[minidx]>cus[idx].arrivedTime){
totalWait+=windows[minidx]-cus[idx].arrivedTime;
windows[minidx]+=cus[idx].servedTime;
}else{
windows[minidx]=cus[idx].arrivedTime+cus[idx].servedTime;//关键,容易忽略
}
idx++;
}
printf("%.1f",totalWait/60.0/validCnt);
;
}
1017 Queueing at Bank的更多相关文章
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- 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 ...
- pat——1017. Queueing at Bank (java中Map用法)
由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...
- 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 1017. Queueing at Bank
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) - priority_queuet
题目如下: Suppose a bank has K windows open for service. There is a yellow line in front of the windows ...
- PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- 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 ...
随机推荐
- LeetCode第[46]题(Java):Permutations(求所有全排列) 含扩展——第[47]题Permutations 2
题目:求所有全排列 难度:Medium 题目内容: Given a collection of distinct integers, return all possible permutations. ...
- 如何将Django部署到Apache服务器上
操作环境: Ubuntu 16.04 Apache 2.4 Django 1.9 Python 2.7 mod_wsgi 前言:本教程纯自己查阅资料后整理,望对大家有帮助! 1. 安装 mod_ws ...
- spring3: AOP 之 通知顺序
如果我们有多个通知想要在同一连接点执行,那执行顺序如何确定呢?Spring AOP使用AspectJ的优先级规则来确定通知执行顺序.总共有两种情况:同一切面中通知执行顺序.不同切面中的通知执行顺序. ...
- poj3311 状压dp+floyd
先floyd预处理一遍dis,枚举所有状态,dp[ i ] [ j ]表示 以 j 为终点的状态 i 使用最小的时间 #include<map> #include<set> ...
- CentOS7 安装ifconfig
As we all know, “ifconfig” command is used to configure a network interfaces in GNU/Linux systems. I ...
- 在Windows下为PHP5.6安装redis扩展
Redis 安装 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统 ...
- 一个css3 DNA 效果
这个效果就是 不断沿 Y 轴旋转 <div id="container"></div> <style> body{ background:bla ...
- 《Drools7.0.0.Final规则引擎教程》第3章 3.2 KIE概念&FACT对象
3.2.1 什么是KIE KIE(Knowledge Is Everything),知识就是一切的简称.JBoss一系列项目的总称,在<Drools使用概述>章节已经介绍了KIE包含的大部 ...
- SVN的详细简单操作
SVN服务器搭建和使用(一) http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html SVN服务器搭建和使用(二) ht ...
- javascript Math.pow 函数 详解 【附】年均增长率计算
语法 Math.pow(x,y) 定义和用法 pow() 方法可返回 x 的 y 次幂的值. 处理简单数学问题 6的4次方等于1296,记作:64=1296; 求值: Math.pow(6,4)=12 ...