【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 ...
 
随机推荐
- jremoting的功能扩展点
			
1 InvokeFilter,实现此接口 可以在consumer端 与provider端的调用过程中拦截住请求调用. 已经实现的InvokeFilter包括 RetryInvokeFilter:实现 ...
 - tensor flow 视频
			
http://v.youku.com/v_show/id_XMTYxMjQ2NTYyNA==.html?spm=a2h1n.8251843.playList.5!19~5~A.siMjNW&f ...
 - 新手C#SQLServer在程序里实现语句的学习2018.08.12
			
从C#中连接到SQL Server数据库,再通过C#编程实现SQL数据库的增删改查. ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤: 第一,使用SqlConnection对象连接数据 ...
 - express.Router
			
[express.Router] 1.可使用 express.Router 类创建模块化.可挂载的路由句柄.Router 实例是一个完整的中间件和路由系统,因此常称其为一个 “mini-app”. 下 ...
 - 破解版ps
			
http://www.sdifen.com/adobe-photoshop-cc.html
 - DFT
			
离散傅里叶变换(Discrete Fourier Transform,缩写为DFT),是傅里叶变换在时域和频域上都呈离散的形式, 将信号的时域采样变换为其DTFT的频域采样.在形式上,变换两端(时域和 ...
 - Maven项目的拆分与聚合
			
---------------------siwuxie095 Maven 项目的拆分与聚合 1.对已有的 Ma ...
 - 【趣】Python获取变量的变量名
			
两种不完美的方式: 用locals,globals 用locals获取变量列表,再遍历比较对象. def namestr(obj): ns = globals() return [name for n ...
 - 【原创】java删除未匹配的文件夹FileFileFilter,FileUtils,删除目录名字不是某个名字的所有文件夹及其子文件夹
			
闲着无聊,写了个小程序. 需求: 举例: 比如我的E盘有一个test的目录,test的结构如下: 要求除了包含hello的目录不删除以外,其他的所有文件夹都要删除. 代码如下: package com ...
 - swift  - VFL
			
1.VFL语法总结: //(1)“H”表示水平方向,“V”表示垂直方向 //(2)“|”表示父视图的边界 //(3)“[]”表示这是一个视图UIView的子类,可以组合多个条件,条件用"() ...