PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
来源:互联网 发布:系统优化提速 编辑:程序博客网 时间:2024/06/06 03:18
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 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 307:55:00 1617:00:01 207:59:59 1508:01:00 6008:00:00 3008:00:02 208:03:00 10Sample Output:
8.2
简单模拟
#include<cstdio>#include<string>#include<cstring>#include<vector>#include<iostream>#include<queue>#include<algorithm>using namespace std;typedef long long LL;const int INF = 0x7FFFFFFF;const int maxn = 1e3 + 10;int n, m, t[maxn], a, b, c, d, ans, cnt;struct point{int x, y;point(int x = 0, int y = 0) :x(x), y(y){}bool operator<(const point&a)const{ return x < a.x; }}f[maxn * 10];int main(){scanf("%d%d", &n, &m);for (int i = 0; i < n; i++){scanf("%d:%d:%d%d", &a, &b, &c, &d);f[i] = point(a * 3600 + b * 60 + c, d * 60);}sort(f, f + n);for (int i = 0; i < m; i++) t[i] = 480 * 60;for (int i = 0; i < n; i++){if (f[i].x >= 17 * 60 * 60) break;int now = 0;for (int j = 1; j < m; j++){if (t[j] < t[now]) now = j;}if (t[now]>f[i].x) ans += t[now] - f[i].x;t[now] = max(t[now], f[i].x) + f[i].y;cnt++;}if (cnt) printf("%.1lf\n", ans / (60.0*cnt)); else printf("0.0\n");return 0;}
- PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
- 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)
- 1017. Queueing at Bank (25)——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1017(Queueing at Bank)
- 【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 1017 Queueing at Bank
- 【PAT 1017】 Queueing at Bank 模拟算法
- PAT 1017 Queueing at Bank (模拟)
- pat 1017. Queueing at Bank (25)
- pat 1017. Queueing at Bank (25)
- 机房重构—七层登录
- cookie与session
- shiro简单配置(转)
- 数据结构和算法经典书籍
- LeetCode219题:Contains Duplicate II
- PAT (Advanced Level) Practise 1017 Queueing at Bank (25)
- 移动端开发需要注意的一些事情
- Linux chown 命令
- 【VS开发】C语言遍历文件夹
- 【模板】(未完成)AVL
- 在windows上部署使用Redis
- 蓝桥 算法训练 ALGO-116最大的算式
- Xcode 常用快捷键总结
- 列表数据导出为Excel