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

题意:银行排队,有 n 个人 m 个窗口,银行营业只在8.00-17.00,对于17.00后来的不给服务,对17.00前的都给服务,即使是超过了17.00,这是一个大坑,没有看出来感觉题目并没有说清楚,知道了这个,用优先队列直接模拟就好,其他的都很简单。

析:先按来的时间排序,然后用优先队列进行模拟。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} const int before = 8 * 60 * 60;
const int after = 17 * 60 * 60;
struct Node{
int s, w;
bool operator < (const Node &p) const{
return s < p.s;
}
};
Node a[maxn]; int main(){
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i){
int h, s, m;
scanf("%d:%d:%d %d", &h, &m, &s, &a[i].w);
a[i].s = h * 3600 + m * 60 + s;
a[i].w *= 60;
}
int sum = 0, cnt = 0;
sort(a, a + n);
priority_queue<int, vector<int>, greater<int> > pq;
for(int i = 0; i < m; ++i) pq.push(before);
int i = 0;
while(i < n){
int x = pq.top(); pq.pop();
if(a[i].s > after) break;
if(x >= a[i].s){
sum += x - a[i].s;
x += a[i].w;
}
else x = a[i].s + a[i].w;
++cnt;
++i;
pq.push(x);
}
if(cnt == 0) printf("0.0\n");
else printf("%.1f\n", sum / 60.0 / cnt);
return 0;
}

  

PAT 1017 Queueing at Bank (25) (坑题)的更多相关文章

  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 (25)-模拟

    有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...

  5. PAT (Advanced Level) 1017. Queueing at Bank (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  6. 【PAT甲级】1017 Queueing at Bank (25 分)

    题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...

  7. 1017 Queueing at Bank (25)(25 point(s))

    problem Suppose a bank has K windows open for service. There is a yellow line in front of the window ...

  8. pat——1017. Queueing at Bank (java中Map用法)

    由PAT1017例题展开: Suppose a bank has K windows open for service. There is a yellow line in front of the ...

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

随机推荐

  1. 使用 key 登录时分开记录操作历史记录

    线上服务器一般都是配置 key 登录,一个账号可以多个工作人员连接,操作命令历史却全部记录在一个文件中,当然后查看某条命令是谁执行的时候就不好查了.这时候我们就可以通过配置 histroy 相关环境变 ...

  2. 基于jwt和角色的访问控制解决方案

    0,主要解决两个问题:1身份验证(防止httpclient拼接请求),2权限控制 1,身份验证使用jwt,在java就是jjwt jwt可以比较好的整合restful,对无状态客户端比较友好,(用se ...

  3. apt安装工具

    apt-cache search package 搜索包 apt-cache show package 获取包的相关信息,如说明.大小.版本等 sudo apt-get install package ...

  4. codeforce 985A Chess Placing(暴力)

    Chess Placing time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Java-Maven-Runoob:Maven 自动化部署

    ylbtech-Java-Maven-Runoob:Maven 自动化部署 1.返回顶部 1. Maven 自动化部署 项目开发过程中,部署的过程包含需如下步骤: 将所的项目代码提交到 SVN 或者代 ...

  6. 【树莓派】RASPBIAN镜像初始化配置

    [树莓派]如何烧录镜像详细版 接上一节,系统已经烧录完毕了,将其放置于树莓派然后运行起来 我是直接接显示器了,若有需要转接头的自行淘宝搜索购买~~电源使用的是5V 2.5A的 首次开机会时间较长 且有 ...

  7. Pandas:表计算与数据分析

    目录 Pandas之Series Pandas之DataFrame 一.pandas简单介绍 1.pandas是一个强大的Python数据分析的工具包.2.pandas是基于NumPy构建的. 3.p ...

  8. 使用PreparedStatement接口实现增删改操作

    直接上下代码: package com.learn.jdbc.chap04.sec02; import java.sql.Connection; import java.sql.PreparedSta ...

  9. 02-20 winform 上传图片并读取图片

    建立一个windows窗体应用程序,在form1界面中拖入两个按钮和一个pictureBox,通过输入输出流来上传图片和显示图片.需要添加一下openFileDialog1. 界面如下: 在cs中写上 ...

  10. js监听文本框内容变化

    js监听文本框内容变化 原理很简单,就是在外部先声明一个用来记录input值的变量,然后每0.1秒比较这个值与input的值,如果发生改变,则运行自己的代码,同时改变变量.从而实现对input值改变的 ...