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 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

tip

模拟题

answer

#include<algorithm>
#include<iomanip>
#include<iostream>
#include<vector>
#include<queue> #define INF 0x3f3f3f3f using namespace std;
int N, K, Begin, End; typedef struct {
int arr, begin, end, pro, wait;
}People;
vector<People> p;
queue<People> 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<<index<<endl;
if(flag){
if(t.arr < Begin){
t.begin = Begin;
t.wait = Begin - t.arr;
}else{
t.begin = t.arr;
t.wait = 0;
}
t.end = t.begin + t.pro;
q[index].push(t);
}else{
if(t.arr < q[index].back().end){
t.begin = q[index].back().end;
t.wait = q[index].back().end - t.arr;
}else{
t.begin = t.arr;
t.wait = 0;
}
t.end = t.begin + t.pro;
q[index].push(t);
}
// cout<<t.arr/(3600)<<":"<<t.arr%(3600)/60<<" "<<t.begin/(3600)<<":"<<t.begin%(3600)/60<<" "<<t.end/(3600)<<":"<<t.end%(3600)/60<<" "<<t.wait/60<<" "<<t.pro/60<<" "<<endl;
} void Pop(){ } void PrintStatus(){
for(int i = 0; i < K; i++){
cout<<i<<endl;
for(int j = 0; j < q[i].size(); j++){
cout<<q[i].front().begin/(60*60)<<":"<<q[i].front().begin%(60*60) /60<<" "<<q[i].front().end/(60*60)<<":"<<q[i].front().end%(60*60) /60<<" "<<q[i].front().wait<<endl;
q[i].push(q[i].front());
q[i].pop();
}
cout<<endl;
}
} int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false); Begin = TranTime("08:00:00");
End = TranTime("17:00:00");
cin>>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<<fixed<<setprecision(1)<<wait/p.size()<<endl;
return 0;
}
/*
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
*/

exprience

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

1017 Queueing at Bank (25)(25 point(s))的更多相关文章

  1. PAT 甲级 1017 Queueing at Bank (25 分)(模拟题,有点思维小技巧,第二次做才理清思路)

    1017 Queueing at Bank (25 分)   Suppose a bank has K windows open for service. There is a yellow line ...

  2. PAT 1017 Queueing at Bank (模拟)

    1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...

  3. PAT 1017 Queueing at Bank[一般]

    1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...

  4. PAT甲级1017. Queueing at Bank

    PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...

  5. MySQL5.7.25(解压版)Windows下详细的安装过程

    大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...

  6. PAT 甲级 1006 Sign In and Sign Out (25)(25 分)

    1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...

  7. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  8. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  9. 【PAT】1060 Are They Equal (25)(25 分)

    1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...

  10. 【PAT】1032 Sharing (25)(25 分)

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

随机推荐

  1. java 连接Kafka报错java.nio.channels.ClosedChannelExcep

    Java 客户端连接Kafka报如下错误 java.nio.channels.ClosedChannelExcep 是由于Kafka server.properties中的advertised.hos ...

  2. ubuntu git 简单入门【转】

    转自:http://blog.chinaunix.net/uid-20718384-id-3334859.html 1. 安装 sudo apt-get install git-core 2.  初始 ...

  3. Mac 升级一次,php 就崩溃一次,有味,苹果....

    Mac升级系统macOS Sierra后PHP不编译 Mac下搭建PHP开发环境(Apache+PHP+MySQL+phpMyAdmin),当Mac 从OS 10.11升级至macOS Sierra( ...

  4. WGS84转大地2000

    1.创建自定义地理(坐标)变换: 2.选择源坐标系和目标坐标系: 3.自定义地理转换方法,选择COORDINATE_FRAME; 4.选择投影工具: 5.在地理变换处选择刚才自定义变换.

  5. Python的set集合详解

    Python 还包含了一个数据类型 -- set (集合).集合是一个无序不重复元素的集.基本功能包括关系测试和消除重复元素.集合对象还支持 union(联合),intersection(交),dif ...

  6. C++类指针类型的成员变量的浅复制与深复制

    本篇文章旨在阐述C++类的构造,拷贝构造,析构机制,以及指针成员变量指针悬空问题的解决.需要读者有较好的C++基础,熟悉引用,const的相关知识. 引言: 类作为C++语言的一种数据类型,是对C语言 ...

  7. 洛谷P2312解方程

    传送门 思路分析 怎么求解呢? 其实我们可以把左边的式子当成一个算式来计算,从1到 $ m $ 枚举,只要结果是0,那么当前枚举到的值就是这个等式的解了.可以通过编写一个 $ bool $ 函数来判断 ...

  8. Codeforces 225C Barcode(矩阵上DP)

    题目链接:http://codeforces.com/contest/225/problem/C 题目大意: 给出一个矩阵,只有两种字符'.'和'#',问最少修改多少个点才能让每一列的字符一致,且字符 ...

  9. gcc/g++ 命令

    gcc & g++现在是gnu中最主要和最流行的c & c++编译器 .g++是c++的命令,以.cpp为主,对于c语言后缀名一般为.c.这时候命令换做gcc即可.其实是无关紧要的.其 ...

  10. (三)使用XML配置SQL映射器

    SqlSessionFactoryUtil.java package com.javaxk.util; import java.io.IOException; import java.io.Input ...