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 ...
随机推荐
- springboot使用fastJson作为json解析框架
springboot使用fastJson作为json解析框架 springboot默认自带json解析框架,默认使用jackson,如果使用fastjson,可以按照下列方式配置使用 〇.搭建spri ...
- [ python ] 初始面向对象
首先,通过之前学习的函数编写一个 人狗大战 的例子. 分析下这个需求,人 狗 大战 三个事情.角色:人.狗动作:狗咬人,人打狗 先创建人和狗两个角色: def person(name, hp, ag ...
- 网页转图片,html生成图片,网页生成图片(基于linnux+phantomjs)和wkhtmltoimage
安装扩展: (1)下面是我在linux上的安装过程,如果没有安装git请先yum install git 安装casperjs cd / git clone git://githu ...
- Effective C++笔记(五):实现
参考:http://www.cnblogs.com/ronny/p/3754755.html 条款26:尽可能延后变量定义式的出现时间 有些对象,你可能过早的定义它,而在代码执行的过程中发生了导常,造 ...
- SCTF 2014 pwn题目分析
因为最近要去做ctf比赛的这一块所以就针对性的分析一下近些年的各大比赛的PWN题目.主防项目目前先搁置起来了,等比赛打完再去搞吧. 这次分析的是去年的SCTF的赛题,是我的学长们出的题,个人感觉还是很 ...
- 包含Winsock2.h出错问题
工程中添加 Winsock2.h 报错 1>c:\program files (x86)\windows kits\8.1\include\shared\ws2def.h(100): warni ...
- 【PAT】1003. 我要通过!(20)
1003. 我要通过!(20) “答案正确”是自动判题系统给出的最令人欢喜的回复.本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”. ...
- 第 17 章 使用API
在本章中,我们将学习如何编写一个独立的程序,并对其获取的数据进行可视化.这个程序将使用Web应用编程接口(API)自动请求网站的特定信息而不是整个网页,再对这些信息进行可视化.由于这样编写的程序始终使 ...
- char *总结
#include <iostream> using namespace std; int main() { char *p[] = {"one","two&q ...
- es6js promise在ie中报错“未定义”
解决办法,我使用https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.auto.min.js直接引入在html中,也可以安装相应的babel-po ...