【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 ...
随机推荐
- python复制文件,路径不存在问题(Windows和linux路径分隔符不统一)
问题: python脚本涉及到复制文件,而我们需要兼容Windows.linux和mac环境 (Windows和linux的路径分隔符不同:通过os.path.sep查看分隔符) 如果用[路径名+ ...
- Required String parameter ' ' is not present
Required String parameter ' ' is not present 报错原因: url中的参数错误. 解决方法: 1.修正url中的参数的值. 2.在Controller层中的@ ...
- linux、centos下查看系统版本、bios版本,内存信息等
1.查看系统版本 [root@localhost ~]# more /etc/issueCentOS release 6.2 (Final)Kernel \r on an \m 2.查看CPU信息 : ...
- ios 8 联系人ABPeoplePickerNavigationController
一. ios 联系人ABPeoplePickerNavigationControllerDelegate方法,新添加下面两个联系人选中方法,适配iOS8需要实现 // Called after a p ...
- 【校招面试 之 C/C++】第27题 C++ 智能指针(三)之 unique_ptr
auto_ptr<string> p1(new string ("auto") : //#1 auto_ptr<string> p2; //#2 p2 = ...
- 【校招面试 之 C/C++】第11题 C++ 纯虚函数
1.纯虚函数 成员函数的形参后面写上=0,则成员函数为纯虚函数. 纯虚函数声明: virtual 函数类型 函数名 (参数表列) = 0: class Person { virtual void Di ...
- golang实现任务分发处理
package main import ( "flag" "fmt" "os" "log" "net/http ...
- VBA json parser[z]
http://www.ediy.co.nz/vbjson-json-parser-library-in-vb6-xidc55680.html VB-JSON: A Visual Basic 6 (VB ...
- poj3017 Cut the Sequence 单调队列 + 堆 dp
描述 把一个正数列 $A$分成若干段, 每段之和 不超过 $M$, 并且使得每段数列的最大值的和最小, 求出这个最小值. 题目链接 题解 首先我们可以列出一个$O(n^2)$ 的转移方程 : $F_i ...
- XE4 for ios 谨慎处理字符串
由于xe4 for ios 里面的字符串处理有变化,具体可以参考官方文档,这两天帮一个朋友调试ios 的 应用,由于没有注意这一块,折腾了很长时间.特此记录下来,希望其他人不要走弯路. 以下面代码为 ...