| 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. 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 |
- 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个人。如果所有窗口都排满了,其他人就在黄线外等待,直到有人完成业务办理。某个窗口的队伍不再排满后,黄线外的人才会选择所有窗口排队人数最少当中:编号最小的那个窗口继续排队。
窗口从8点开始营业,17点不再办理还未处于服务状态的人
求每个人都是在什么时候结束业务办理的时间,如无办理,输输出Sorry。
思路
经典队列思想
注意点
所有人,只要选择了在某个窗口排队,就不会再去其他窗口,哪怕其他窗口已经没有人了。
所有窗口17.00开始不再服务新的用户办理,但还在服务的人,仍然将其业务办理完成。
- #include
- using namespace std;
- int findWindow(); // 找到符合要求的窗口
- void Clear(); // 当前最早结束的一个窗口
- bool endTime; // 判断所有窗口是否都结束工作
- int N,MAXSIZE,K,Q,nowTime=480,result[1001]; // result 结果存储
- queue
int,int>> window[21]; // 存储每个窗口办理人员的 id + time - int main()
- {
- int num,key;
- cin >> N >> MAXSIZE >> K >> Q;
- for(int z=1;z<=K;z++){
- cin >> num;
- if(endTime) continue;
- key = findWindow();
- window[key].push({z,num});
- }
-
- while (!endTime) Clear();
-
- while (Q--){
- cin >> num;
- if(result[num]>0) printf("%02d:%02d\n",result[num]/60,result[num]%60);
- else puts("Sorry");
- }
- return 0;
- }
- int findWindow(){
- int flag = 999,op=0;
- for(int z=1;z<=N;z++){
- if(window[z].size()
size() - op = z;
- flag = window[z].size();
- }
- }
- if(flag==999 && !endTime){
- Clear();
- return findWindow();
- }
- return op;
- }
-
- void Clear()
- {
- int minTime = 201314;
- for(int z=1;z<=N;z++){
- if(window[z].empty()) continue;
- minTime = min(minTime,window[z].front().second);
- }
-
- if(nowTime+minTime>=1020) endTime = true;
- if(endTime){
- for(int z=1;z<=N;z++) if(!window[z].empty()){
- result[window[z].front().first] = nowTime+window[z].front().second;
- }
- }else{
- nowTime += minTime;
- for(int z=1;z<=N;z++) if(!window[z].empty()){
- window[z].front().second -= minTime;
- if(window[z].front().second==0){
- result[window[z].front().first] = nowTime;
- window[z].pop();
- }
- }
- }
- }
