【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 HttpClient进行POST请求(HTTPS)
目前,要为另一个项目提供接口,接口是用HTTP URL实现的,最初的想法是另一个项目用jQuery post进行请求. 但是,很可能另一个项目是部署在别的机器上,那么就存在跨域问题,而jquery的p ...
- Python frozenset() 函数
Python frozenset() 函数 Python 内置函数 描述 frozenset() 返回一个冻结的集合,冻结后集合不能再添加或删除任何元素. 语法 frozenset() 函数语法: ...
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别
SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...
- 利用X.509证书对XML进行加密和签名
综述 XML加密和签名技术应用非常广泛. ASP.NET 使用XML加密对配置信息进行加密:InfoPath使用XML签名对表单进行签名:Web服务使用XML加密和签名对SOAP消息进行加 ...
- 使用一般处理程序(IHttpHandler)制作图片水印
做网站的时候经常需要将图片加上网站名称的水印.这样做可以使别人转载图片的时候出现图片出处 ,利于网站宣传.但是如果利用ps来一个一个加水印工作量非常浩大,而且修改了之后就没法还原.这 篇教程教大家利用 ...
- 15-matlab矩阵运用
from scipy.spatial import Delaunay from mpl_toolkits.mplot3d import Axes3D import numpy as np import ...
- 将php数据下载csv文件
<?php $sales = array( array( 'Northeast', '2005-01-01', '2005-02-01', 12.54 ), array( 'Northwest' ...
- php 下 html5 XHR2 + FormData + File API 上传文件
FormData的作用: FormData对象可以帮助我们自动的打包表单数据,通过XMLHttpRequest的send()方法来提交表单.当然FormData也可以动态的append数据.FormD ...
- Spring框架之log日志的使用
1.Spring框架也需要引入日志相关的jar包 * 在spring-framework-3.0.2.RELEASE-dependencies/org.apache.commons/com.sprin ...
- 还不好好读书吗?清华3D录取通知书出炉,还能动!
近日,清华大学2018录取通知书“亮相”!看完后,网友直呼:哪里可以买到? 打开录取通知书 3D“二校门”跃然纸上 由清华师生共同打造.手工定制.独一无二的2018新版录取通知书来了!在新版录取通知书 ...