PAT 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 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) (坑题)的更多相关文章
- 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 ...
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT 1017 Queueing at Bank[一般]
1017 Queueing at Bank (25)(25 分)提问 Suppose a bank has K windows open for service. There is a yellow ...
- PAT甲题题解-1017. Queueing at Bank (25)-模拟
有n个客户和k个窗口,给出n个客户的到达时间和需要的时长有空闲的窗口就去办理,没有的话就需要等待,求客户的平均时长.如果在8点前来的,就需要等到8点.如果17点以后来的,则不会被服务,无需考虑. 按客 ...
- PAT (Advanced Level) 1017. Queueing at Bank (25)
简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 使用 Git 来备份 MySQL 数据库
使用 Git 来备份 MySQL 数据库 使用 mysqldump 导出 sql 文件 使用 git pull 提交到仓库 将脚本加入任务管理 mysqldump 导出时需要以下参数. --skip- ...
- 《大教堂和集市》笔记——为什么一个本科生业余作品却成了全世界最流行的操作系统之一Linux?
1. Eric Raymond有一篇著名文章<大教堂和集市>(The Cathedral and the Bazaar). 他说,世界上的建筑可以分两种:一种是集市,天天开放在那里,从无到 ...
- Jave 文件介绍
Java程序的基本组成单元是类,有class声明,类体中包括属性和方法. 一个Java文件中可以有多个class声明,但由public修饰的类只能有一个,并且类名作为该文件的名称. 每一个应用程序都必 ...
- You-Get 一键下载全网视频资源
下载视频 无论是单纯的下载视频收藏,还是以便离线收看,都离不开“下载”,好的工具让你把注意力更好的放在视频的本身,而不用考虑要如何下载视频.下载视频从来不乏方法,之前也介绍了下载 Youtube ...
- nginx config的多个config配置
在我们的一台服务器上,一个nginx服务器下面可能跑着许多许多的项目; 那么就需要配置多个对应的配置 端口号 已经文件入库目录等等 那么项目多了以后,把这些项目都写到一个文件里 到后期难以查看与管理 ...
- module_param 用于动态开启/关闭 驱动打印信息
1.定义模块参数的方法: module_param(name, type, perm); 其中,name:表示参数的名字; type:表示参数的类型; perm:表示参数的访问权限 ...
- vue-cli脚手架build目录下utils.js工具配置文件详解
此文章用来解释vue-cli脚手架build目录中的utils.js配置文件 此配置文件是vue开发环境的wepack相关配置文件,主要用来处理css-loader和vue-style-loader ...
- vue-cli脚手架config目录下index.js配置文件详解
此文章介绍vue-cli脚手架config目录下index.js配置文件 此配置文件是用来定义开发环境和生产环境中所需要的参数 关于注释 当涉及到较复杂的解释我将通过标识的方式(如(1))将解释写到单 ...
- Maven的安装及配置、Maven在Eclipse中的配置
一.需要准备的东西 1. JDK 2. Eclipse 3. Maven程序包 二.检查JAVA安装 三.安装Maven 下载apache-maven-3.5.3-bin.zip解压即可. 四.配置M ...
- Python 约束 , 自定义异常 , 加密 , 日志
约束 约束 , 约束其派生类: 保证派生类中必须编写send方法 , 不然执行可能就会报错 Python中 语法: class BaseMessage(object): def send(self ...