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:
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.
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.
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.
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
08:07
08:06
08:10
17:00
Sorry
题意:有N个窗口,每个窗口一次最多排M个人,超出NM的人需要某个窗口少于M个人时候可以进入,且进入时会选择当前人数最少的窗口,如果相同,那么选编号小的窗口,总共有K个人,每个人有对应所需时间,最后有Q次询问,每次询问输出当前ID的人的完成时间。
每个窗口早上8:00开始,17:00结束,如果某个人在17:00后被受理,那么输出Sorry
解析:模拟队列,可以用双端队列,十分方便,我们可以把第一批的人先处理,后面暴力每个时间点,对应更新即可。
#include
using namespace std;
const int N=1005;
int w[N],ans[N],T[N];
void solve()
{
int n,m,k,Q;
deque q[30],qq[30];//qq为实时队列
scanf("%d%d%d%d",&n,&m,&k,&Q);
for(int i=1;i<=k;i++) scanf("%d",&w[i]);//每个人所需时间
int num=1,ren=0;//分别记录窗口编号和当前放了几个人
for(int i=1;i<=k;i++)
{
if(q[num].size()=17*60) printf("Sorry\n");
else printf("%02d:%02d\n",ans[id]/60,ans[id]%60);
}
}
int main()
{
int t=1;
while(t--) solve();
return 0;
}