PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968
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 <bits/stdc++.h>
using namespace std; int N, M; struct Node{
int time;
int wait;
}; vector<Node> v; bool cmp(const Node &a, const Node &b) {
return a.time < b.time;
} int main() {
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i ++) {
Node n;
int h, m, s, t;
scanf("%d:%d:%d %d", &h, &m, &s, &t);
n.time = h * 3600 + m * 60 + s;
n.wait = t * 60; if(n.time <= 61200) v.push_back(n);
} vector<int> win(M, 28800);
//memset(win, 28800, sizeof(win));
sort(v.begin(), v.end(), cmp); //for(int i = 0; i < v.size(); i ++)
//printf("%d %d\n", v[i].time, v[i].wait); double total = 0.0;
for(int i = 0; i < v.size(); i ++) {
int temp = 0, minn = win[0];
for(int j = 1; j < M; j ++) {
if(win[j] < minn) {
minn = win[j];
temp = j;
}
}
if(win[temp] <= v[i].time)
win[temp] = v[i].time + v[i].wait;
else {
total += (win[temp] - v[i].time);
win[temp] += v[i].wait;
}
} //cout << total;
if(v.size() == 0) printf("0.0\n");
else printf("%.1lf\n", total / 60.0 / v.size());
return 0;
}
把所有时间转换成秒 把来的人按照来的时间排序 在 17:00:00 之后的排除 更新最快结束的窗
PAT 甲级 1017 Queueing at Bank的更多相关文章
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- 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甲级——A1017 Queueing at Bank
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 ...
- PAT甲级1017题解——模拟排序
题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- 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 ...
- 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 ...
随机推荐
- 洛谷P1223
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;int b[ ...
- Python yield的用法
yield的英文单词意思是生产,刚接触Python的时候感到非常困惑,一直没弄明白yield的用法. 只是粗略的知道yield可以用来为一个函数返回值塞数据,比如下面的例子: def addlist( ...
- dd测试
time dd if=/dev/zero of=/root/test.db2 bs=200K count=10000 oflag=dsync
- [luogu 5300][bzoj 5502] [GXOI/GZOI2019] 与或和
题面 思路还是挺容易想的, 只是由于我还是太\(naive\)了一点不会做只会打暴力吧...... 题目要我们求所有子矩阵的\(and\)值之和与\(or\)值之和, 一看之下似乎不好入手, 我们慢慢 ...
- oracle 迁移
一.创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建. create directory exp_shengchan as '/home/oracle/exp_shen ...
- mysql5.6.8源码安装
内核: [root@opop ~]# cat /etc/centos-release CentOS release 6.8 (Final)[root@opop ~]# uname -aLinux op ...
- FreeRTOS任务函数
FreeRTOS的任务函数原型如下:void ATaskFunction(void *pvParameters); void ATaskFunction(*pvParameters){;; //函数可 ...
- 搭建SSH服务
1.安装 ssh-server 通过命令进行安装:sudo apt-get install openssh-server 在安装时遇到问题,根据提示,执行命令:sudo apt-get update, ...
- C#创建自己的扩展方法
C#可以创建自己的扩展方法Extension Method: 参考这篇<判断是否为空然后赋值>http://www.cnblogs.com/insus/p/8004097.html 里,前 ...
- EZ 2018 06 17 NOIP2018 模拟赛(十九)
这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...