1017. Queueing at Bank (25)——PAT (Advanced Level) Practise
来源:互联网 发布:大淘营淘宝复制软件 编辑:程序博客网 时间:2024/06/06 15:40
题目信息
1017.Queueing at Bank (25)
时间限制 400 ms
内存限制 65536 kB
代码长度限制 16000 B
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
解题思路
把时间转化成秒,超出17:00的时间剔除,然后按秒模拟
AC代码
#include <cstdio>#include <algorithm>using namespace std;struct node{ long long a, w; bool operator<(const node& b)const{ return a < b.a; }}s[10005];long long k[105];long long n, m, a, b, c, t, id, wait, waitp;int main(){ scanf("%lld%lld", &n, &m); for (int i = 0; i < n; ++i){ scanf("%lld:%lld:%lld %lld", &a, &b, &c, &s[id].w); s[id].w *= 60; s[id].a = a*60*60+b*60+c; if (s[id].a >= 61200){ --id; } ++id; } sort(s, s + id); c = 28800; while (t < id){ bool flag = true; for (int i = 0; i < m; ++i){ if (k[i]) --k[i]; } while (flag && t < id && s[t].a <= c){ flag = false; for (int i = 0; i < m; ++i){ if (!k[i]) { flag = true; a = i; } } if (flag){ k[a] = s[t].w; wait += c - s[t].a; ++t; } } ++c; } printf("%.1f\n", 1.0*wait/60/id); return 0;}
- 1017. Queueing at Bank (25) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
- PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
- 【PAT Advanced Level】1017. Queueing at Bank (25)
- 浙大 PAT Advanced level 1017. Queueing at Bank (25)
- 【PAT】【Advanced Level】1017. Queueing at Bank (25)
- 【PAT Practise】1017. Queueing at Bank (25)
- PAT (Advanced) 1017. Queueing at Bank (25)
- PAT (Advanced) 1017. Queueing at Bank (25)
- PAT (Advanced Level) 1017. Queueing at Bank (25) 银行排队等待时间
- Pat(Advanced Level)Practice--1017(Queueing at Bank)
- pat 1017. Queueing at Bank (25)
- pat 1017. Queueing at Bank (25)
- 【PAT】1017. Queueing at Bank (25)
- PAT 1017. Queueing at Bank (25)
- PAT A 1017.Queueing at Bank (25)
- android自定义View绘制天气温度曲线
- 黑马程序员_java用java进行复制文件(考虑使用多线程),能系统自带快吗??
- ls 命令详解
- 关于web性能的思考与分享[06]——【原创】fis3构建工具使用教程(01)
- opencv(1)
- 1017. Queueing at Bank (25)——PAT (Advanced Level) Practise
- 编程心得02
- 数据库的一些操作
- java类中的执行顺序
- 【UI进阶】关于IB的理解,不知道这样是否可以
- linux app应用如何检测USB设备热插拔
- 10009---bean 之间的关系:继承;依赖
- Codeforces Round #333 (Div. 1)
- HDU ACM 2138 How many prime numbers