作者:到几百元_309 | 来源:互联网 | 2023-08-18 19:40
题目描述:SupposeabankhasNwindowsopenforservice.Thereisayellowlineinfrontofthewindowswhichdevid
题目描述:
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:
①The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line.
②Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.
③Customeri will take Ti minutes to have his/her transaction processed.
④The first N customers are assumed to be served at 8:00am.
Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.
For example, suppose that a bank has 2 windows and each window may have 2 customers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer1 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.
At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.
Input Specification:
Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (≤20, number of windows), M (≤10, the maximum capacity of each line inside the yellow line), K (≤1000, number of customers), and Q (≤1000, number of customer queries).
The next line contains K positive integers, which are the processing time of the K customers.
The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.
Output Specification:
For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17]
and MM is in [00, 59]
. 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.
Sample Input:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
Sample Output:
08:07
08:06
08:10
17:00
Sorry
算法描述:队列 时间模拟
题目大意:
银行有n个窗口 黄线内每个窗口可以站m个人 黄线内最多n * m 个人
其他人需要等待在黄线外 k顾客的数量 q询问次数
黄线内每个窗口等待人数相等时,优先进入序号小的窗口
#include
#include
using namespace std;
int n, m, k, q; //窗口数 每个窗口人数 总人数 查询次数
struct customers
{
int pro_time, out_time = 0; //办事时长 离开时长(0为办业务失败)
}c[1010];
int main()
{
int curnum = 1; //当前需要排列的人次
cin >> n >> m >> k >> q;
queue que[n];//窗口
for(int i = 1 ; i <= k ; i ++) scanf("%d", &c[i].pro_time);
for(int time = 480 ; time <1020 ; time ++) //分钟为单位 8点到下午5点
{
// 送客
for(int i = 0 ; i if(que[i].size())
{
int j = que[i].front();
if(c[j].out_time == time)
que[i].pop();
}
// 入队
for(int i = 1 ; i <= m ; i ++) //排
for(int j = 0 ; j {
if(que[j].size() if(curnum <= k)
{
que[j].push(curnum); // 当前黄线外的等候者进入第j个窗口排队
curnum ++;
}
}
// 迎客
for(int i = 0 ; i if(que[i].size()) //当前窗口有顾客
{
int j = que[i].front();
if(c[j].out_time == 0) //当前顾客并非正在办理业务
c[j].out_time = time + c[j].pro_time;
}
}
while(q --)
{
int x;
cin >> x;
if(c[x].out_time == 0) cout <<"Sorry" < else
{
printf("%02d:%02d\n", c[x].out_time / 60, c[x].out_time % 60);
}
}
return 0;
}