【PAT Advanced Level】1014. Waiting in Line (30)
简单模拟题,注意读懂题意就行
#include <iostream>
#include <queue>
using namespace std; #define CUSTOMER_MAX 1000+1
#define INF 0x6fffffff #ifndef LOCAL
// #define LOCAL
#endif LOCAL int n; // number of windows <=20
int m ;// queue capacity <=10
int k; // customers <=1000
int q; // query times <=1000 int ProcessTime[CUSTOMER_MAX]; //
queue<int> que[20];
queue<int >Wait[20];
int currTime = 0;
int LeaveTime[CUSTOMER_MAX];
int Timebase[20] = {0}; int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n>>m>>k>>q;
for(int i=0;i<k;i++)
{
cin>>ProcessTime[i];
}
int index;
int top = 0;
for(int i = 0;i<2*k;i++)
{
int min_len = m;
if(top !=k) // if there are any customer not in line
{
for(int j=0;j<n;j++)
{
if(min_len > que[j].size() )
{
min_len = que[j].size();
index = j;
}
}
}
if(min_len != m) // find minimum queue
{
que[index].push(top);
Wait[index].push(ProcessTime[top]);
top++;
}else // no queue available or no customer not in line, then customer pop
{
long min_wait = INF;
bool empty = true;
for(int j=0;j<n;j++)
{
if(Wait[j].empty()) continue;
if(min_wait > Timebase[j]+Wait[j].front()) // find current minimum wait time
{
min_wait = Timebase[j]+Wait[j].front();
index = j;
empty = false;
}
}
if(empty) break;
Timebase[index] += Wait[index].front();
LeaveTime[que[index].front()] = Timebase[index];
que[index].pop();
Wait[index].pop();
}
} //60*9
int qq;
for(int i=0;i<q;i++)
{
cin>>qq;
qq--;
if(LeaveTime[qq]-ProcessTime[qq]<60*9)
{
int hour = LeaveTime[qq]/60;
int second = LeaveTime[qq]%60;
printf("%02d:%02d\n",8+hour,second);
}
else
printf("Sorry\n");
} #ifdef LOCAL
system("PASUE");
#endif LOCAL return 0;
}
【PAT Advanced Level】1014. Waiting in Line (30)的更多相关文章
- 【PAT Advanced Level】1008. Elevator (20)
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...
- 【PAT Advanced Level】1004. Counting Leaves (30)
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #inc ...
- 【PAT Advanced Level】1006. Sign In and Sign Out (25)
关键在于清空字符数组和使用scanf进行输入 #include <stdio.h> #include <string.h> #include <fstream> # ...
- 【PAT Advanced Level】1015. Reversible Primes (20)
转换进制&&逆序可以在一起进行,有一点技巧,不要用十进制数来表示低进制,容易溢出. #include <iostream> #include <vector> ...
- 【PAT Advanced Level】1011. World Cup Betting (20)
简单模拟题,遍历一遍即可.考察输入输出. #include <iostream> #include <string> #include <stdio.h> #inc ...
- 【PAT Advanced Level】1013. Battle Over Cities (25)
这题给定了一个图,我用DFS的思想,来求出在图中去掉某个点后还剩几个相互独立的区域(连通子图). 在DFS中,每遇到一个未访问的点,则对他进行深搜,把它能访问到的所有点标记为已访问.一共进行了多少次这 ...
- 【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 (30)-模拟,优先级队列
题意:n个窗口,每个窗口可以排m人.有k为顾客需要办理业务,给出了每个客户的办理业务时间.银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候.如果有一个窗口用户服务结束,黄线外的客户就进来一个 ...
- 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 ...
随机推荐
- java 可伸缩阻塞队列实现
最近一年多写的最虐心的代码.必须好好复习java并发了.搞了一晚上终于测试都跑通过了,特此纪念,以资鼓励! import java.util.ArrayList; import java.util.L ...
- Linux就业技术指导(七):游戏类运维重点流程解析
一,某游戏公司例行上线与更新流程示例 例行维护/更新流程 1.1 更新前天 提前确认好要更新的是什么,更新会有人通知你,一般是运营人员 比如:我们明天做什么什么更新 1.2 第2天更新 一般固定点更新 ...
- HTML的实际演练1
1.HTML介绍 一个网站的建立都是HTML的,例如大家可以打开F12就可以看到浏览器的一个开发者模式,就可以看到网页的源代码了: 当然这网页他有很多的标签编写组成的,有的显示文字,段落,有的是个超链 ...
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别
SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...
- 支付宝SDK ios快捷支付
配置PartnerConfig.h的参数 //合作身份者id,以2088开头的16位纯数字 #define PartnerID @"" //收款支付宝账号 #define Sell ...
- SQL时间格式化 转载备用~
Sel1 取值后格式化{0:d}小型:如2005-5-6{0:D}大型:如2005年5月6日{0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...
- 11-matlba-bellman-ford;地杰斯特拉
求最短路: 1.bellman-ford: %求s到各点的最短距离 function Dist = Bellman_Ford(s) load cityJuli; for i = 1:154 Dist( ...
- webstorm 2017 激活破解
2017-06-15更新 之前都是使用2017.2.27的方法,版本是2017.1.1,还没提示过期,但是根据评论说这个链接已经失效了,评论也给出了个新地址:http://idea.iteblog.c ...
- 品味性能之道<六>:图形化SQL分析工具
在上一章里,重点分享了命令行SQL分析工具的使用方法.在本章将重点分享PL/SQL的SQL分析工具. 一.如何打开PL/SQL执行计划 开启PL/SQL这工具,推荐如下方法: 点击 ...
- vc到vs2015消息函数
afx_msg LRESULT OnMyIconNotify(WPARAM wParam,LPARAM lParam); vc6 可以是void vs2015不可以 ON_MESSAGE(MYWM_ ...