1.该题是一道银行排队模拟题目,银行8点开门,17点关门。在17:00之前没有得到处理,则不再处理,如果已经得到处理,因为输出的范围为format HH:MM where HH is in [08, 17] and MM is in [00, 59],所以一直处理到17:59.
2.银行排队时间模拟,采用合适的结构进行编程
[c language=”++”]
struct customNode{
int process;//还需要处理多长的时间,每经过一次循环,–
int cost;//该用户需要处理的时间
string finished;//完成的时间
customNode() :process(0), cost(0), finished(""){};
};
[/c]
3.超过17:00(包括17:00)不再接受新用户,已经在处理的用户可以一直处理到17:59
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.
- Customer[i] will take T[i] 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 custmers 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
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
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
[c language=”++”]
//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
//#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
using namespace std;
/*
2 1 4 4
599 540 1 2
1 2 3 4
*/
struct customNode{
int process;//还需要处理多长的时间,每经过一次循环,–
int cost;//该用户需要处理的时间
string finished;//完成的时间
customNode() :process(0), cost(0), finished(""){};
};
string int2str(int a)
{//数字转string
char b = a / 10 + ‘0’;
char c = a % 10 + ‘0’;
string ans = "1";
ans += b;
ans += c;
return ans.substr(1);
}
string recordTime(int a)
{//int转时间
int hour = a / 60 + 8;
int min = a % 60;
string ans = int2str(hour) + ":" + int2str(min);
//cout << ans << endl;
return ans;
}
int main(void) {
int n, m, k, q;//n为银行窗口数,m为每个窗口的黄线内容量,k个客户,q是查询序列
cin >> n >> m >> k >> q;
vector<customNode> custom(k);
for (int i = 0; i < k; i++)
{//输入用户需要处理的时间
cin >> custom[i].process;
custom[i].finished = "";
custom[i].cost = custom[i].process;//初始化用户需处理的时间
}
//窗口队列,每个窗口为一个队列
vector<queue<int>> window(n);
int input = 0;
for (; input < n*m&input < k; input++)
{//把客户压进窗口的队列
window[input%n].push(input);
}
//10个小时,按照一分钟一分钟地进行计算
for (int i = 0; i < 599; i++)
{//一直可以处理到17:59
bool allFinished = true;//全部处理完毕
for (int j = 0; j < n; j++)
{
if (window[j].empty()) continue;//队列为空意味着等待队列无人了。因为窗口一有位置,就会马上插入等待队列中的人。
allFinished = false;//窗口中仍有需要处理的用户
if (i >= 540)
{//超过17:00的不再接收新的用户处理
int tmp = window[j].front(); //读取当前窗口的第一个用户
if (custom[tmp].process == custom[tmp].cost)
{//如果这些用户还没有被处理,即process==cost,现在已经超过17点,那么直接弹出,不再处理
while (!window[j].empty())
{//后面的用户肯定也没有处理,直接弹出
window[j].pop();
}
continue;//该窗口已经为空,直接下一个窗口
}
}
int p = window[j].front();//读取当前窗口的第一个用户
custom[p].process–;//该用户处理时间减1分钟
if (custom[p].process == 0)
{//如果处理时间为0,证明客户处理完毕
custom[p].finished = recordTime(i + 1);
window[j].pop();//
if (input<k&&i<539)
{//如果input小于k,即仍有人需要服务,并且时间小于17:00,则进行排队处理
window[j].push(input++);
}
}
}
}
for (int i = 0; i < q; i++)
{//输入查询队列
int query;
cin >> query;
if (custom[query – 1].process != 0)
cout << "Sorry" << endl;
else
cout << custom[query – 1].finished << endl;
}
return 0;
}
[/c]