PAT甲级1014. Waiting in Line
PAT甲级1014. Waiting in Line
题意:
假设银行有N个窗口可以开放服务。窗前有一条黄线,将等候区分为两部分。客户要排队的规则是:
每个窗口前面的黄线内的空间足以包含与M个客户的一条线。因此,当所有N行都满时,
所有的客户(和包括)(NM + 1)第一个将不得不等待在黄线后面的一行。
每个客户将选择最短的行,以便在穿过黄线时等待。如果长度相同的两行以上,客户将始终选择数字最小的窗口。
客户[i]将在T [i]分钟内处理他/她的交易。
前N名客户被假定在上午8:00送达。
现在给予每个客户的处理时间,您应该告诉客户完成业务的确切时间。
例如,
假设一个银行有2个窗口,每个窗口可能有两个人在黄线内等待。分别有1个,2个,6个,4个和3分钟的交易有5个客户等待交易。在上午08:00,客户1在window1服务,而客户2在window2服务。
Customer3将在window1之前等待,customer4将在window2之前等待。客户5将等待黄线后面。
在08:01,客户1完成,客户5进入窗口1之前的行,因为这条线似乎更短。 Customer2将在08:02,customer4在08:06,customer3在08:07离开,最后在08:10退出customer5。
输入
每个输入文件包含一个测试用例。每个案例以包含4个正整数的行开始:N(<= 20,窗口数),M(<= 10,黄线内每行的最大容量),K(<= 1000,客户数) ,和Q(<= 1000,客户查询数)。
下一行包含K个正整数,
这是K客户的处理时间。
最后一行包含Q正整数,表示正在询问他们完成交易时间的客户。客户的编号从1到K.
输出
对于每个Q客户,他们的交易完成时间一行打印,
格式为HH:MM,其中HH在[08,17]中,MM在[00,59]中。请注意,由于银行在17:00之后每天关闭,对于那些在17:00之前无法上门的客户,您必须输出“抱歉”。
思路:
用优先队列模拟排队。
题目中有个地方需要注意,就是只要在17:00前到的都可以服务。包括17:00点。这个地方比较骚。
另外在黄线内就不能移动了,无论你旁边的队伍是否已经空了。
ac代码:
C++
// pat1014.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<unordered_map>
using namespace std;
int cusk[1005];
int win[22];
struct custom {
int id;
int time;
int window;
};
struct customcmp {
bool operator()(const custom &a, const custom &b)
{
if (a.time != b.time)
{
return a.time > b.time;
}
else
{
return a.window > b.window;
}
}
};
int main()
{
int n, m, k, q;
priority_queue<custom, vector<custom>, customcmp> queue;
memset(win, 0, sizeof(win));
memset(cusk, 0, sizeof(cusk));
cin >> n >> m >> k >> q;
for (int i = 1; i <= k; i++)
{
cin >> cusk[i];
}
for (int i = 0; i < m; i++)
{
for (int j = 1; j <= n; j++)
{
custom cus;
if (win[j] >= 540 || win[j] < 0)
win[j] = -1;
else
win[j] += cusk[i * n + j];
cus.id = i * n + j;
cus.time = win[j];
cus.window = j;
cusk[i * n + j] = win[j];
queue.push(cus);
}
}
int cur = n * m + 1;
while (cur <= k)
{
custom cc = queue.top();
custom cus;
queue.pop();
if (win[cc.window] >= 540 || win[cc.window] < 0)
win[cc.window] = -1;
else
win[cc.window] += cusk[cur];
cus.id = cur;
cus.window = cc.window;
cus.time = win[cc.window];
cusk[cur] = win[cc.window];
queue.push(cus);
cur++;
}
int id,tempres;
while (q--)
{
cin >> id;
tempres = cusk[id];
if (tempres < 0) cout << "Sorry" << endl;
else
{
int hour = 8, minute = 0;
hour += tempres / 60;
minute += tempres % 60;
printf("%02d:%02d\n", hour, minute);
}
}
return 0;
}
PAT甲级1014. Waiting in Line的更多相关文章
- PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)
1014 Waiting in Line (30 分) Suppose a bank has N windows open for service. There is a yellow line ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- PAT甲级——A1014 Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PAT 1014 Waiting in Line (模拟)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- 1014 Waiting in Line (30分)
1014 Waiting in Line (30分) Suppose a bank has N windows open for service. There is a yellow line i ...
- PTA (Advanced Level) 1014 Waiting in Line
Waiting in Line Suppose a bank has N windows open for service. There is a yellow line in front of th ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- PAT 1014. Waiting in Line
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PAT 1014 Waiting in Line (模拟)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
随机推荐
- Spring如何解析Dubbo标签
1. 要了解Dubbo是如何解析标签的,首先要清楚一点就是Spring如何处理自定义标签的,因为Dubbo的标签可以算是Spring自定义标签的一种情况: 2. Spring通过两个接口来解析自定义的 ...
- centos6.5 使用 rpm 安装 mysql
从mysql网站下载mysql rpm安装包(包括server.client) 1.安装server rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm 强制安 ...
- 查看压缩包内容tar -tf
linux 压缩文件内容查看 分类:Linux | 标签: linux 压缩文件内容查看 2012-03-14 22:01阅读(1243)评论(0) 1. zipinfo 执行zipinfo ...
- 进程一些命令pstree,ps,pstack,top
1. pstree pstree以树结构显示进程$ pstree -p work | grep adsshd(22669)---bash(22670)---ad_preprocess(4551)-+- ...
- Erasure Coding(纠删码)深入分析 转
1.前言 Swift升级到2.0大版本后宣称开始支持纠删码,这其实是一个很有意义的特性,主要是能够在一定程度上解决3副本空间浪费太多的问题.因为3副本这一点是swift推广的最大障碍之一,成本的增加吓 ...
- PHP 分割字串 Function 的速度比較(substr/sscanf/preg_match)---substr最快!
固定長度的字串(假設是 06481a63041b578d702f159f520847f8), 要照固定格式做切割, 使用 PHP 要怎麼切會比較快? 註: 要將此字串切成 => 06 / 48 ...
- 【UOJ】#79. 一般图最大匹配
题解 板子!我相信其实没人来看我的板子!但是为了防止我忘记,我还是要写点什么 我们考虑二分图,为什么二分图就能那么轻松地写出匹配的代码呢?因为匹配只会发生在黑点和白点之间,我们找寻增广路,必然是一黑一 ...
- Centos7中一次性安装开发者工具
这里使用组安装包,一次性安装所有开发者工具. 1.查看有那些组安装包可用. yum grouplist | more 2.搜索一下有哪些和development有关. yum grouplist | ...
- 双缓冲解决控制台应用程序输出“闪屏”(C/C++,Windows)
使用 C 语言编写游戏的小伙伴们想必起初都要遇到这样的问题,在不断清屏输出数据的过程中,控制台中的输出内容会不断地闪屏.出现这个问题的原因是程序对数据处理花掉的时间影响到了数据显示,或许你可以使用局部 ...
- 七牛刷新接口PHP实现
<?php require_once '../autoload.php'; use Qiniu\Auth; use Qiniu\Http\Client; $accessKey = 'access ...