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 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 (≤104) - 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 <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <queue>
#include <string>
#include <set>
#include <map>
using namespace std;
const int maxn = ;
int n,k;
queue<int> q[maxn];
struct person {
int arr;
int arr_const;
int start;
int pro;
int wait=;
};
bool cmp(person p1, person p2) {
return p1.arr < p2.arr;
}
vector<person> v;
int h, m, s, process;
int main(){
int count = ,time = ;
cin >> n >> k;
for (int i = ; i < n; i++) {
person p;
scanf("%d:%d:%d %d", &h, &m, &s, &process);
getchar();
time = * h + * m + s;
p.arr = time;
p.start = time;
p.arr_const = time;
p.pro = process*;
p.wait = ;
if (time > * )continue;
v.push_back(p);
count++;
}
sort(v.begin(), v.end(), cmp);
int now = *;
for (int i = ; i < count; i++) {
if (v[i].arr < now) {
v[i].wait = now - v[i].arr;
v[i].start = now;
v[i].arr = now;
}
}
int now_time = * ;
int fast_k = ;
for (int i = ; i < count - k; i++) {
int fast = ;
for (int j = ; j < i+k; j++) {
if (v[j].start + v[j].pro < fast) {
fast = v[j].start + v[j].pro;
fast_k = j;
}
}
v[fast_k].start = ;
now_time = fast;
if (now_time > v[i + k].arr) {
v[i + k].wait += now_time - v[i + k].arr;
v[i + k].start = now_time;
}
} float mean = ;
for (int i = ; i < count; i++) {
mean += v[i].wait;
}
if (count == )printf("0.0");
else {
mean /= count;
printf("%.1f", mean/);
}
system("pause");
return ;
}
注意点:又是一道逻辑挺简单的题,还是花了1个多小时才ac,前半部分思路是没问题的,后面窗口等待走歪了,一直在顾客上做文章,其实只要把每个窗口的开始服务时间更新,到的比窗口服务时间早的就等待,否则直接开始不用等。
PAT A1017 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 ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- 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 ...
- [PAT] A1017 Queueing at Bank
[思路] 1:将所有满足条件的(到来时间点在17点之前的)客户放入结构体中,结构体的长度就是需要服务的客户的个数.结构体按照到达时间排序. 2:wend数组表示某个窗口的结束时间,一开始所有窗口的值都 ...
- 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[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- pat1017. Queueing at Bank (25)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
随机推荐
- hash table (youtube 2)
https://www.youtube.com/watch?v=jEdaduyLLqY
- Git 实战手册(一): 批量修改log中的提交信息
本文须知 教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 背景介绍 事情的起源是这样的:迷恋的谷歌的我最近申请了一个新的 googl ...
- 《Head First设计模式》批注系列(一)——观察者设计模式
最近在读<Head First设计模式>一书,此系列会引用源书内容,但文章内容会更加直接,以及加入一些自己的理解. 观察者模式(有时又被称为模型-视图(View)模式.源-收听者(List ...
- canvas-0translate.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- DOM事件-调用函数
通过调用函数改变其内容: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> ...
- ionic 开发解决ios上qq客服链接不跳转或者跳转到appstore
不能跳转的情况需要 在ionic项目根目录下,打开config.xml文件,在<access origin="*" />后添加<allow-navigation ...
- CMake笔记(一)
CMake,比makefile更方便,虽然手写makefile同样重要 CMake的所有命令均出现在CMakeList.txt中,注意名字不要写错,并置于源代码目录中 # CMake 最低版本号要求 ...
- opencv学习网站[国外网站]+ 各种学习资料
1.Learn OpenCV 使用C++和python和opencv结合编写的教程,上面有丰富的小实验,并且有完整的源码. 2.pyimagesearch python+opencv编写的实例教程,有 ...
- eclipse显示代码行数
最近做的手机APP正在进行最后一部分了,在一个类中估计要写上千行代码,来回的拉动滚动条太麻烦了,于是发现为什么我得eclipse不显示代码行数呢 其他C什么的编译器都显示的. 于是百度了一下,一下子 ...
- 《Inside C#》笔记(十二) 委托与事件
C#的委托与C++的函数指针类似,但委托是类型安全的,意味着指针始终会指向有效的函数.委托的使用主要有两种:回调和事件. 一 将委托作为回调函数 在需要给一个函数传递一个函数指针,随后通过函数指针调用 ...