1014. Waiting in Line (模拟)
n个窗口就有n个队列,模拟这n个队列就可以了。需要注意的是,一个人在选择排队窗口的时候,他会选择排队人数最少的窗口,如果存在多个窗口排队的人数相同,那么他会选择编码最小的窗口。
Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.这句话的意思就是:对于那些不能再17:00之前开始服务的人,请输入"Sorry"。换句话说,就是那些能在五点钟之前开始服务及时服务结束时间超过五点也是可以的!!!所以在计算时,假设$f(i)$表示第$i$个用户结束服务的时间,$serv(i)$表示用户的服务时间,如果满足条件$f(i) - serv(i) \ge (17 - 8) \times 60$,则该客户不能完成服务!!
AC代码
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = + ;
int n, m, k, q;
int serv[maxn], done[maxn];
int line[][maxn], s[maxn], f[maxn]; int main() {
while(scanf("%d%d%d%d", &n, &m, &k, &q) == ) {
for(int i = ; i <= k; i++)
scanf("%d", &serv[i]);
for(int i = ; i <= n; i++) {
s[i] = f[i] = ;
done[i] = serv[i];
line[i][] = i;
}
for(int i = n+; i <= k; i++) {
bool full = ;
int cnt = m + , bet = ;
for(int j = ; j <= n; j++) {
if(f[j] - s[j] + < m) {
full = ;
if(f[j] - s[j] + < cnt) {
cnt = f[j] - s[j] + ;
bet = j;
}
}
}
if(full) {
int over_time = INF;
bet = ;
for(int j = ; j <= n; j++) {
int id = line[j][s[j]];
if(done[id] < over_time) {
bet = j;
over_time = done[id];
}
}
s[bet] += ;
}
f[bet] += ;
line[bet][f[bet]] = i;
done[i] = done[line[bet][f[bet]-]] + serv[i]; }
int qID;
for(int i = ; i < q; i++) {
scanf("%d", &qID);
if(done[qID] - serv[qID] >= (-)*)
printf("Sorry\n");
else
printf("%02d:%02d\n", done[qID]/+, done[qID]%);
}
}
return ;
}
如有不当之处欢迎指出!
1014. Waiting in Line (模拟)的更多相关文章
- 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 (模拟)
1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- 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甲级1014. Waiting in Line
PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...
- 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 ...
- PAT A 1014. Waiting in Line (30)【队列模拟】
题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...
- 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为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...
- 1014 Waiting in Line (30)(30 point(s))
problem Suppose a bank has N windows open for service. There is a yellow line in front of the window ...
随机推荐
- junit4X系列--Exception
原文出处:http://www.blogjava.net/DLevin/archive/2012/11/02/390684.html.感谢作者的无私分享. 说来惭愧,虽然之前已经看过JUnit的源码了 ...
- Ceph,TFS,FastDFS,MogileFS,MooseFS,GlusterFS 对比
系统整体对比 对比说明 /文件系统 TFS FastDFS MogileFS MooseFS GlusterFS Ceph 开发语言 C++ C Perl C C C++ 开源协议 GPL V2 GP ...
- javascript:将URL的参数列表解析为一个对象
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 第三方模块paramiko的使用
"Paramiko" is a combination of the Esperanto words for "paranoid" and "frie ...
- 10个实用的 Linux 网络和监控命令[转]
本文列出了10个基础的每个Linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nslooku ...
- web.config文件中配置数据库连接的两种方式
web.config文件中配置数据库连接的两种方式 标签: 数据库webconfig 2015-04-28 18:18 31590人阅读 评论(1)收藏举报 分类: 数据库(74) 在网站开发 ...
- div仿td标签属性
链接:https://pan.baidu.com/s/1kW1At9d 密码:g0he 这里说的div是指固定大小的,动态往里面填充文字的时候,文字一直水平垂直居中(换行也是).就和td标签一样.当然 ...
- python3操作socketserver
socketserver是标准库中的一个高级模块,用于网络客户端与服务器的实现.模块中,已经实现了一些可供使用的类. 在python3中,导入socketserver模块使用的命令: import s ...
- CentOS6.9编译安装nginx1.4.7
1.系统安装开发包组和zlib-devel,关闭iptables [root@bogon ~]# yum groupinstall -y "Development Tools" [ ...
- 简单实现ASP.Net MVC网页播放音乐
<div> @*音乐*@ <audio id="warning-sound" loop="loop" src="/Areas/Map ...