1017. Queueing at Bank
2015-11-22 17:35
393 查看
1017. Queueing at Bank (25)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; struct Time { int h; int m; int s; }; int timeToSecond(Time t) { return t.h*3600 + t.m*60 + t.s; } struct Customer { int arivel_time; int server_time; bool operator < (const Customer & A) const { return arivel_time < A.arivel_time; } }buf[10002]; int ans[10002];//保存顾客的等待时间 int que[102];//window,保存顾客的编号 int main() { freopen("F://Temp/input.txt", "r", stdin); int n, k; scanf("%d%d", &n, &k); Time tmp; for(int i = 0; i < n; i ++) { scanf("%d:%d:%d", &tmp.h, &tmp.m, &tmp.s); buf[i].arivel_time = timeToSecond(tmp); int server; scanf("%d", &server); buf[i].server_time = server * 60; } sort(buf, buf+n); for(int i = 0; i < n; i ++) que[i] = -1; for(int i = 0; i < n; i ++) ans[i] = -1; int count = 0, t; for(t = 28800; t <= 864000 && buf[count].arivel_time <= 61200; t ++) { for(int i = 0; i < k; i ++) { if(que[i] != -1) { int temp = que[i]; if((buf[temp].arivel_time + ans[temp] + buf[temp].server_time) == t) que[i] = -1; } } for(int i = 0; i < k; i ++) { if(que[i] == -1 && t >= buf[count].arivel_time) { que[i] = count; ans[count] = t - buf[count].arivel_time; count ++; } } } int sum = 0, i; for(i = 0; i < n; i ++) { if(ans[i] == -1) break; else sum += ans[i]; } if(i == 0) printf("0\n"); else printf("%.1lf\n", (double)sum/i/60); return 0; }
[/code]
相关文章推荐
- ios UITableView 入门
- Easyui简单布局
- UIButton
- Arduino 学习上拉电阻和下拉电阻遇到的问题
- UIBezierPath绘制图形
- java获取request的 ip port
- UIView
- LeetCode 063 Unique Paths II
- Android(13)java中的线程回顾,Android线程,主线程(UI线程)
- POJ1679The Unique MST(次小生成树)
- 第九章 UI布局管理器
- break continue详解
- 第八章 高级UI组件
- easyui环境搭建02
- Unique Paths II-leetcode
- cocoapods 0.35.0 版本 报错 Parsing unable to continue due to parsing error:
- UIBezierPath的自定义路径绘图
- LeetCode 062 Unique Paths
- CALayer 为什么选择 cg 开头 而 不选择 UI 开头
- Hbuilder--让手爽,飞一般的编码(二)