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 (模拟)的更多相关文章

  1. 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 ...

  2. PAT 1014 Waiting in Line (模拟)

    1014. Waiting in Line (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  3. 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 ...

  4. PAT甲级1014. Waiting in Line

    PAT甲级1014. Waiting in Line 题意: 假设银行有N个窗口可以开放服务.窗前有一条黄线,将等候区分为两部分.客户要排队的规则是: 每个窗口前面的黄线内的空间足以包含与M个客户的一 ...

  5. 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 ...

  6. PAT A 1014. Waiting in Line (30)【队列模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1014 思路: 直接模拟类的题. 线内的各个窗口各为一个队,线外的为一个,按时间模拟出队.入队. 注 ...

  7. 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 ...

  8. PAT甲题题解-1014. Waiting in Line (30)-模拟,优先级队列

    题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...

  9. 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 ...

随机推荐

  1. centos7安装python3.6

    安装python3.6可能使用的依赖 # yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sql ...

  2. ueditor显示内容末尾有多余标记的解决

    问题: 最近用了百度的ueditor文本编辑器,出现一个问题,用ueditor存数据到数据库都正常,但是重新读取后赋值到ueditor却会在末尾多出 "> 这两个符号.赋值方式如下: ...

  3. php curl模拟登陆抓取数据

    http://www.cnblogs.com/zengguowang/p/6814474.html

  4. echo 0000

    一个奇怪的问题,正常状态下如果sql插入失败,则输出0000,代码如下: $stmt=$db->prepare("insert into message(user,title,cont ...

  5. 2018-01-28-M个本地工作点代码同步到N个GIT远端

    layout: post title: 2018-01-28-M个本地工作点代码同步到N个GIT远端 key: 20180128 tags: IT GIT modify_date: 2018-01-2 ...

  6. ferror,perror,cleaner

    1.ferror 函数原型: int ferror(FILE *fp) 功能:测试文件是否出现错误 返回值:未出错是0:出错为非0. 每次调用文件输入输出函数,均产生一个新的ferror函数值 fop ...

  7. event跨进程通信

    event天生的弱势,只有mutex可以感知丢失,就是将另一个进程关闭了,event无法感知. event1: #include <stdio.h> #include <stdlib ...

  8. 程序员之殇 —— (Are you afraid of me? Don't be.)灵感=神秘感

    Are you afraid of me? (你们怕我吗?) Don't be.(不用怕) I am a programmer who just won't die.(我是不会死的程序员) 自从跟踪到 ...

  9. ssh 设置私钥实现两台linux主机无密码访问

    在服务器主机上(称为A主机) 创建公钥与私钥: ssh-keygen -t rsa 一路回车,如果想设置密码短语,在提示 passphrase 的时候设置密码短语 查看生成的公钥及私钥: ls ~/. ...

  10. rtmp推流时间戳兼容问题

    一直用简单的librtmp或者其他开源推流实现方式.没有太关注细节问题.直到最近一次测试长时间推流.遇到了3字节时间戳溢出问题,即时间戳超过0xffffff,服务器断开. 复现方式:用yasea推流到 ...