PAT 甲级 1017 Queueing at Bank
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968
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 (≤104) - 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
代码:
#include <bits/stdc++.h>
using namespace std; int N, M; struct Node{
int time;
int wait;
}; vector<Node> v; bool cmp(const Node &a, const Node &b) {
return a.time < b.time;
} int main() {
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i ++) {
Node n;
int h, m, s, t;
scanf("%d:%d:%d %d", &h, &m, &s, &t);
n.time = h * 3600 + m * 60 + s;
n.wait = t * 60; if(n.time <= 61200) v.push_back(n);
} vector<int> win(M, 28800);
//memset(win, 28800, sizeof(win));
sort(v.begin(), v.end(), cmp); //for(int i = 0; i < v.size(); i ++)
//printf("%d %d\n", v[i].time, v[i].wait); double total = 0.0;
for(int i = 0; i < v.size(); i ++) {
int temp = 0, minn = win[0];
for(int j = 1; j < M; j ++) {
if(win[j] < minn) {
minn = win[j];
temp = j;
}
}
if(win[temp] <= v[i].time)
win[temp] = v[i].time + v[i].wait;
else {
total += (win[temp] - v[i].time);
win[temp] += v[i].wait;
}
} //cout << total;
if(v.size() == 0) printf("0.0\n");
else printf("%.1lf\n", total / 60.0 / v.size());
return 0;
}
把所有时间转换成秒 把来的人按照来的时间排序 在 17:00:00 之后的排除 更新最快结束的窗
PAT 甲级 1017 Queueing at Bank的更多相关文章
- PAT甲级1017. Queueing at Bank
PAT甲级1017. Queueing at Bank 题意: 假设一家银行有K台开放服务.窗前有一条黄线,将等候区分为两部分.所有的客户都必须在黄线后面排队,直到他/她轮到服务,并有一个可用的窗口. ...
- 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甲级——A1017 Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- 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 (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- PAT甲级1017题解——模拟排序
题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...
- 【PAT甲级】1017 Queueing at Bank (25 分)
题意: 输入两个正整数N,K(N<=10000,k<=100)分别表示用户的数量以及银行柜台的数量,接下来N行输入一个字符串(格式为HH:MM:SS)和一个正整数,分别表示一位用户到达银行 ...
- 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 ...
- PAT 1017. Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
随机推荐
- log4j2 yml
1.log4j2默认加载文件为log4j2.xml 2.要使用yml加载需添加依赖 <!-- https://mvnrepository.com/artifact/com.fasterxml.j ...
- CSS3渐变——径向渐变
上节在<再说CSS3渐变——线性渐变>和大家一起学习了CSS3 Gradient中径向渐变最新语法(称得上是W3C的标准语法)相关知识以及其基本使用.今天我们在这一篇中主要和大家一起来了解 ...
- day14 Python百分号字符串拼接
拼接 # -*- coding:utf8 -*- #%s字符串,%d数字msg = '%s am %s my %s is %s'% (2,"charon","pluto& ...
- nginx反向代理与Real-IP和X-Forwarded-For.txt
本文作者张开涛.为保障<亿级流量网站架构核心技术>一书内容的连续性,有些需要读者了解的内容,或者书的补充和引申内容,会通过二维码嵌入的方式引导读者阅读学习.大家可以关注作者公众号“开涛的博 ...
- ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1)
ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1) To Bottom In this Document Symptom ...
- Python将数据渲染到docx文档指定位置
超简单Python将指定数据插入到docx模板渲染并生成 最近有一个需求,制作劳动合同表,要从excel表格中将每个人的数据导入到docx劳动合同中,重复量很大,因此可以使用python高效解决.为了 ...
- 个人css编写规范
前言:最近在做微信小程序,因为公司小,就我一个人弄前端的东西,js和页面都是我来弄,结果那天后台的人看到我的js代码,说我的代码写得不规范,函数什么的都很乱,弄得我羞愧难当,幸亏没看我的css,其实我 ...
- ES6生成器函数generator
ES6生成器函数generator generator是ES6新增的一个特殊函数,通过 function* 声明,函数体内通过 yield 来指明函数的暂停点,该函数返回一个迭代器,并且函数执行到 y ...
- Android 动态的给Button、TextView、ImageView等控件设置了background后,再设置padding属性时该属性不起作用
也许大家遇到这样一个问题,有时我们根据业务需要在一个ViewGroup中动态的(程序运行过程中)添加View.例如添加Button,就需要给Button添加background.padding.mar ...
- 洛谷 P2835 刻录光盘
题目链接 https://www.luogu.org/problemnew/show/P2835 题目描述 在JSOI2005夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘 ...