PAT甲级1017. Queueing at Bank

题意:

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

假设一个客户不能占用1个小时以上的窗口。

现在考虑到每个客户的到达时间T和处理时间P,您应该告诉所有客户的平均等待时间。

输入:

每个输入文件包含一个测试用例。对于每种情况,

第一行包含2个数字:N(<= 10000) - 客户总数,K(<= 100) - 窗口数。然后N行跟随,每个包含2次:HH:MM:SS - 到达时间,P - 客户的处理时间(以分钟为单位)。这里HH在[00,23]的范围内,MM和SS都在[00,59]中。

假设没有两个客户同时到达。

请注意,银行营业时间为08:00至17:00。任何人提前到达,必须等到08:00,任何人来得太晚(17:00:01之间或之后)将不会服务也不会计入平均水平。

输出:

对于每个测试用例,

在一行中打印所有客户的平均等待时间,在几分钟内精确到小数点后1位。

思路:

模拟排队。我用的优先队列。跟前面一道题有点像。

注意点:

  • 只要在17:00或者17:00前到都可以被服务
  • 都在17:00后到达的话,注意0为除数的情况

ac代码:

C++

// pat1017.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<unordered_map>
#include<iomanip> using namespace std; struct custom
{
double arriving;
int process;
double ending;
int window;
custom() : arriving(0), process(0), ending(0), window(0) {};
}; vector<custom> cus; struct mycmp {
bool operator()(custom& a, custom& b) const
{
return a.ending> b.ending;
}
}; static bool cmp(custom a, custom b)
{
return a.arriving < b.arriving;
} double counttime(string a, string b)
{
double ahour, bhour, aminute, bminute, asecond, bsecond;
ahour = stoi(a.substr(0, 2));
aminute = stoi(a.substr(3, 2));
asecond = stoi(a.substr(6, 2));
bhour = stoi(b.substr(0, 2));
bminute = stoi(b.substr(3, 2));
bsecond = stoi(b.substr(6, 2)); double res = 0;
res = (ahour - bhour) * 60 + (aminute - bminute) + (asecond - bsecond) / 60;
return res;
} int main()
{
int n, m;
string arrive;
priority_queue<custom, vector<custom>, mycmp> q; cin >> n >> m;
for (int i = 0; i < n; i++)
{
custom c;
cin >> arrive >> c.process;
c.arriving = counttime(arrive, "08:00:00");
if (c.process > 60) c.process = 60;
cus.push_back(c);
} sort(cus.begin(), cus.end(),cmp); for (int i = 0; i < m; i++)
{
custom c;
//c.window = i;
c.ending = 0;
q.push(c);
} int len = cus.size();
int pos = 0;
double wait = 0;
while (pos < len && cus[pos].arriving <= 540)
{
custom t = q.top();
q.pop();
//if (t.ending > 540) break; //只要来了排在队伍就可以被服务
if (cus[pos].arriving >= t.ending)
{
wait += 0;
cus[pos].ending = cus[pos].arriving + cus[pos].process;
}
else
{
wait += t.ending - cus[pos].arriving;
cus[pos].ending = t.ending + cus[pos].process;
}
//cus[pos].window = t.window;
q.push(cus[pos]);
pos++;
} double res;
if (pos == 0) res = 0; //防止所有客户17:00后到,0为除数
else res = wait / pos;
cout << fixed << setprecision(1) << res << endl;
//for (int i = 0; i < cus.size(); i++)
// cout << cus[i].arriving << " " << cus[i].process << endl;
return 0;
}

PAT甲级1017. Queueing at Bank的更多相关文章

  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

    https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...

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

  4. PAT 1017 Queueing at Bank[一般]

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

  5. PAT 1017 Queueing at Bank (模拟)

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

  6. PAT甲级1017题解——模拟排序

    题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...

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

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

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

随机推荐

  1. React 16 源码瞎几把解读 【前戏】 为啥组件外面非得包个标签?

    〇.看前准备 1.自行clone react最新代码 2.自行搭建一个能跑react的test项目 一.看表面:那些插件 如何解析JSX 有如下一段代码: // ---- hearder.jsx 组件 ...

  2. 非交互式shell脚本案例-实现自主从oracle数据库获取相关数据,并在制定目录生成相应规则的文件脚本

    get_task_id 脚本内容 #!/usr/bin/expect#配置登陆数据库的端口set port 22#配置登陆数据库的ip地址set oracleip 10.0.4.41#配置数据库实例名 ...

  3. 7.Python3标准库--文件系统

    ''' Python的标准库中包含大量工具,可以处理文件系统中的文件,构造和解析文件名,还可以检查文件内容. 处理文件的第一步是要确定处理的文件的名字.Python将文件名表示为简单的字符串,另外还提 ...

  4. 应用nslookup命令查看A记录、MX记录、CNAME记录和NS记录

    https://blog.csdn.net/qq_38058202/article/details/80468688

  5. centos 下tomcat 自动启动

    1.修改start.sh文件 vim /usr/local/tomcat8/bin/startup.sh 在文件头增加以下内容: #!/bin/sh # chkconfig: 2345 97 00 # ...

  6. powerdeginer 默认name 为 common

    在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中写中文,在Code中写英文.Name用来显 示,Code在代码中使用,但Comment中的文字会保 ...

  7. python部分内容存档

    笨办法学python. 1 Ec6字符串和文本... 1 ec7. 1 ec8. 1 Ec9. 1 Ec10 转义字符... 1 Ec11提问... 1 raw_input和input的区别... 1 ...

  8. pyqt5之QColorDialog颜色对话框最简单使用

           设置窗体背景颜色 QWidget.setStyleSheet('QWidget {background-color:#88ab45}') 颜色对话框取得颜色值是十六进制. col=QCo ...

  9. AM335x内核模块驱动之LED

    在Ubuntu的任意可操作的文件才建立text目录 在text中建立zyr-hello.c: #include<linux/kernel.h> #include<linux/modu ...

  10. 在学习HTML——form表单中的label标签时的一点小体会

    在我啃了一遍书本之后,开始了在慕课看视频的过程,从最开始的HTML+CSS的基础课程看起,在第5-9小节讲到了form表单的label标签, 首先看一下慕课的讲解:  label 标签不会向用户呈现任 ...