1017. Queueing at Bank (25)
来源:互联网 发布:linux 串口 select 编辑:程序博客网 时间:2024/04/28 07:26
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
将时间全部转化为距离00:00:00的秒数,可以简化计算。
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <limits>using namespace std;struct Customer{int arrive;int process;int leave;Customer(int a, int p) : arrive(a), process(p), leave(0){}bool operator < (const Customer& rhs) const{return arrive < rhs.arrive;}};int main(){int n, k;scanf("%d%d", &n, &k);vector<Customer> customers;for(int i = 0; i < n; ++i){int h, m, s, p;scanf("%d%*c%d%*c%d%d", &h, &m, &s, &p); int arrive = h * 3600 + m * 60 + s;if(arrive <= 17 * 3600){ customers.emplace_back(arrive, p * 60);}}sort(customers.begin(), customers.end());vector<int> timePassed(k, 8 * 3600);vector<int> windows(k, 0); n = (int)customers.size();for(int i = 0; i < n; ++i){int minTime = numeric_limits<int>::max();int index = -1;for(int j = 0; j < k; ++j){if(minTime > windows[j]){index = j;minTime = windows[j];}} if(timePassed[index] < customers[i].arrive){ timePassed[index] = customers[i].arrive + customers[i].process; }else{ timePassed[index] += customers[i].process; } customers[i].leave = timePassed[index]; windows[index] = customers[i].leave;}int total = 0;for(auto& c : customers){ total += c.leave - c.process - c.arrive;} total /= n;double sum = total / 60 + (total % 60) / 60.0;printf("%.1f", sum);return 0;}
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- 1017. Queueing at Bank (25)
- [置顶]【结果很简单,过程很艰辛】记阿里云Ons消息队列服务填坑过程
- [置顶]C#中使用Redis不同数据结构的内存占有量的疑问和对比测试
- Python 基础——字符串
- CodeForces-630A. Again Twenty Five!【找规律】
- Reinstall msdtc on Windows
- 1017. Queueing at Bank (25)
- kali安装后详细配置
- 值得推荐的C/C++框架和库
- MVC的学习用PPT
- 假脱机技术
- JAVA多线程-对象及变量的并发访问(二)volatile关键字
- 技术大牛小星星眼中的项目管理
- 创建安卓app的30个经验教训
- Android笔记 标题栏ActionBar