博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1017 Queueing at Bank (25)(25 point(s))
阅读量:4495 次
发布时间:2019-06-08

本文共 2718 字,大约阅读时间需要 9 分钟。

problem

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

tip

模拟题

answer

#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f using namespace std;int N, K, Begin, End;typedef struct { int arr, begin, end, pro, wait;}People;vector
p;queue
q[110];int TranTime(string t){ int hour = 0, minute = 0, second = 0; hour = (t[0]-'0')*10+t[1]-'0'; minute = (t[3]-'0')*10+t[4]-'0'; second = (t[6]-'0')*10+t[7]-'0'; return (hour)*60*60 + minute*60 + second;}bool Comp(People a, People b){ return a.arr < b.arr;}void Push(People &t){ int min = INF, index = 0; bool flag = false; for(int i = 0; i < K; i++){ if(q[i].empty()) { index = i; flag = true; continue; } if(q[i].back().end < min && !flag) { min = q[i].back().end; index = i; } }// cout<
<
>N>>K; for(int i = 0; i < N; i++){ string time; int pro; cin>>time>>pro; People tp; tp.arr = TranTime(time); tp.pro = pro*60; if(tp.arr > End) continue; p.push_back(tp); } sort(p.begin(), p.end(), Comp); for(int i = 0; i < p.size(); i++){ Push(p[i]);// PrintStatus(); }// PrintStatus(); float wait = 0.0; for(int i = 0; i < p.size(); i++){ wait += p[i].wait / 60.0; } cout<
<
<

exprience

  • 应该在30分钟内解决的一个简单模拟题,因为写代码时思考的太少而导致debug时间太长。

转载于:https://www.cnblogs.com/yoyo-sincerely/p/9314708.html

你可能感兴趣的文章
正则表达式
查看>>
Date类
查看>>
基本类型的数值转换
查看>>
集合、泛型、增强for
查看>>
Public Key Retrieval is not allowed错误
查看>>
Unable to load authentication plugin 'caching_sha2_password'.错误
查看>>
The server time zone value '乱码' 错误
查看>>
vuex
查看>>
react-router-dom
查看>>
react 的三大属性
查看>>
Redux知识
查看>>
Eric6安装问题解决
查看>>
利用python制作在线视频播放器遇到的一些问题
查看>>
require.js的用法
查看>>
基础语言知识C++
查看>>
如何使电脑彻底崩溃!!!!(不要干坏事哦)
查看>>
简单练习题
查看>>
记账本,C,Github,service
查看>>
迷之阶梯
查看>>
约数定理(two)
查看>>