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 ...
随机推荐
- 南邮综合题writeup
http://teamxlc.sinaapp.com/web3/b0b0ad119f425408fc3d45253137d33d/index.php fuckjs直接console得到地址 http: ...
- 图解IIS8上解决ASP.Net第一次访问慢的处理
- Java Eclipse 配置
1.清除多余记录 最近用eclipse打包jar的时候,需要指定一个main函数.需要先运行一下main函数,eclipse的Runnable JAR File Specification 下的Lau ...
- 监控MYSQL主从同步配置中监控从库运行状态的脚本
代码如下: #!/bin/bash #Check MySQL Slave's Runnning Status #Crontab time 00:10 MYSQLPORT=`netstat -na|gr ...
- mysql cursor游标的使用,实例
mysql被oracle收购后,从mysql-5.5开始,将InnoDB作为默认存储引擎,是一次比较重大的突破.InnoDB作为支持事务的存储引擎,拥有相关的RDBMS特性:包括ACID事务支持,数据 ...
- MVC公开课 – 2.查询,删除 (2013-3-15广州传智MVC公开课)
查询 /Controller/HomeController.cs /// <summary> /// 查询 文章 列表 /// </summary> /// <retur ...
- day2 字典常用的方法
字典创建的方式: (1)d1 = {"k1":"v1","k2":"v2","k3":&qu ...
- import xxx from 和 import {xxx} from的区别
1.vue import FunName from ‘../xxx’ 1.js export defualt function FunName() { return fetch({ url: '/ar ...
- Node.js的Buffer那些你可能不知道的用法
在大多数介绍Buffer的文章中,主要是围绕数据拼接和内存分配这两方面的.比如我们使用fs模块来读取文件内容的时候,返回的就是一个Buffer: fs.readFile('filename', fun ...
- 如何解决pytorch 编译时CUDA版本与运行时CUDA版本不对应
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 如何解决pytorch 编译时CUDA版本与运行时CUDA版本不对应 如果pytorch的编译时 ...