PAT甲级1017. Queueing at Bank
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的更多相关文章
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K w ...
- 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 ...
随机推荐
- layui实现类似于bootstrap的模态框功能
以前习惯了bootstrap的模态框,突然换了layui,想的用layui实现类似于bootstrap的模态框功能. 用到了layui的layer模块,例如: <!DOCTYPE html> ...
- apache2启动失败(Failed to start The Apache HTTP Server.)解决方案
不知道如何启动apache2就启动不来了. 如下图所示: 即使卸载了重新装也是如此 经过测试卸载并清除软件包的配置即可解决 sudo apt-get purge apache2 sudo apt-g ...
- 笔记本自开wifi设置
笔记本自开wifi设置 是这样的有些笔记本他自身就可以放出热点供其他的小伙伴们连接,不用非得去下专门的工具有些笔记本的网卡是自带支持双收发的(这里注意我指的是有些笔记本不是全部) 命令我已经写出来了 ...
- Deploy Openstack with RDO and Change VNC console to Spice
Deploy Openstack with RDO and Change VNC console to Spice host os: centOS 7 server config network an ...
- google浏览器中,使用clockwork 来调试
参考:https://laravel-china.org/courses/laravel-package/1976/debugging-tool-under-chrome-itsgoingdclock ...
- ASP.NET Core 2.0 MVC 发布部署--------- CentOS7 X64 具体操作
.Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...
- POJ 3026 Borg Maze(Prim+bfs求各点间距离)
题目链接:http://poj.org/problem?id=3026 题目大意:在一个y行 x列的迷宫中,有可行走的通路空格’ ‘,不可行走的墙’#’,还有两种英文字母A和S,现在从S出发,要求用 ...
- python爬取网易云音乐歌单音乐
在网易云音乐中第一页歌单的url:http://music.163.com/#/discover/playlist/ 依次第二页:http://music.163.com/#/discover/pla ...
- Nginx 502错误:upstream sent too big header while reading response header from upstream
原因: 在使用Shiro的rememberMe功能时,服务器返回response的header部分过大导致. 解决方法: https://stackoverflow.com/questions/238 ...
- span文字里面自动换行时怎么办
可以用white-space:nowrap来强制文字不换行,知道遇到<br>为止