1、题目描述
H公司为了提升员工的用餐体验,在食堂引入了一家网红餐厅,但是该餐厅容量有限,员工用餐时可能会排队等候。
假设该餐厅只提供2人桌、4人桌、8人桌、10人桌这几种餐桌,每种餐桌的数量根据输入确定,员工用餐时,需要有空余的餐桌时才能用餐,现在需要你设计一个排队提示系统,提示员工需要等候多久进行用餐,排队规则如下:
- 员工就餐时,以团队进行排队用餐,当团队人数大于10人时,超过该餐厅接待规格,该餐厅不进行接待
- 根据团队到达时间进行取号,取号时,只能取大于等于团队人数,且最接近团队人数的餐桌的号,比如团队人数为5,则取8人桌的号3、当有对应的空闲桌时,则团队开始用餐,用餐时间固定为30分钟,且一个餐桌同时只能一个团队用餐。用餐结束后,对应的餐桌空闲,可以给其它团队使用
- 当团队排队超过10分钟(含10分钟),对应的餐桌没有空闲,但是有其它大餐桌空闲时,会分配最接近团队人数的大餐桌,否则继续等待。比如团队取的4人桌的号,等待10分钟以上店,8人桌和10人桌均有空闲,此时将使用8人桌进行用餐
- 餐厅营业时间为11点00分到21点00分,如果到达时间在11点00分之前,则统一在11点时按照到达先后顺序进行排队,如果在21点00分之后还未用餐,则餐厅不再接待。
备注:任何情况下当两个团队同时满足条件就餐时,优先安排先到达的团队就餐。
2、解答要求
时间限制:
C/C++1000ms,其他语言:2000ms
内存限制:C/C++ 256MB,其他语言:512MB
输入
- 第一行:4个无符号整数,分别为2人桌、4人桌、8人桌、10人桌的数量;用例保证每个整数的范围均>=1且<=10
- 第二行:1个整数,为总共有多少团队用餐;用例保证该整数范围为>=1且<= 90
- 第三行~第N行:每行4个整数,分别为团队ID、团队达到时间的小时数、团队到达时间的分钟数、团队人数;用例保证输入一定是按时间先后顺序输入,且团队ID和达到时间都不相同,且团队到达时间保证在10点00分到22点00分(包含10点00分和22点00分)之间且合法
输出
每一行输出2个整数,分别为团队ID和团队等待时间;
备注:按团队到达的顺序输出团队等待时间;若是不接待的团队,则输出等待时间-1
示例1
输入:
1 1 1 1
4
1 11 20 3
2 11 21 5
5 11 22 3
4 11 23 2
输出:
1 0
2 0
5 10
4 0
示例2
输入:
1 1 1 1
4
1 10 50 9
2 11 20 11
3 11 22 8
4 11 23 8
输出:
1 10
2 -1
3 0
4 10
3、代码
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
struct clients
{
int ID;
int timeCome;
int personNum;
int timeLeft;
int waitTime;
int startWait;
clients(int a = 0, int b = 0, int c = 0, int d = 0, int e = 700, int f=0) :
ID(a), timeCome(b), personNum(c), timeLeft(d), waitTime(e), startWait(f)
{
}
};
class CanTing
{
public:
CanTing()
{
int time = 0;
seatInfo = vector<vector<int>>(4);
string line;
getline(cin, line);
stringstream ss;
ss << line;
int num, i = 0;
while (ss >> num)
seatInfo[i++] = vector<int>(num);
cin >> num;
for (int i = 0; i < num; i++)
{
clients temp;
int hour, min;
cin >> temp.ID;
cin >> hour >> min >> temp.personNum;
time = hour * 60 + min;
temp.startWait = time < 660 ? 660-time : 0;
if(time > 1260) temp.personNum = 11;
temp.timeCome = time>=660 ? time:660;
queueClients.push(temp);
}
printInfo();
while (queueClients.size())
{
serverClient();
}
}
void printInfo()
{
for (int i = 0; i < queueClients.size(); i++)
{
cout << queueClients.front().ID << " " << queueClients.front().timeCome << " " << queueClients.front().personNum << endl;
queueClients.push(queueClients.front());
queueClients.pop();
}
for (auto seats : seatInfo)
{
for (auto seat : seats)
cout << seat << " ";
cout << endl;
}
}
void serverClient()
{
clients temp = queueClients.front();
if (temp.personNum <= 2)
{
addClient(0, temp, temp.startWait);
IsServe(temp);
}else if(temp.personNum <= 4)
{
addClient(1, temp, temp.startWait);
IsServe(temp);
}else if(temp.personNum <= 8)
{
addClient(2, temp, temp.startWait);
IsServe(temp);
}
else if(temp.personNum <= 10)
{
addClient(3, temp, temp.startWait);
IsServe(temp);
}else
{
cout<<temp.ID<<" "<<-1<<endl;
}
queueClients.pop();
}
bool addClient(int seatNum, clients &temp, int wait)
{
for (auto &seat : seatInfo[seatNum])
{
if (seat <= temp.timeCome+wait)
{
seat = temp.timeCome + 30;
temp.timeLeft = seat;
temp.waitTime = wait;
return true;
}
else
{
temp.waitTime = min(temp.waitTime, seat - temp.timeCome+wait);
}
}
if(temp.waitTime>=10 && seatNum<3) return addClient(seatNum+1, temp, 10);
return false;
}
void IsServe(clients temp)
{
if(temp.waitTime + temp.timeCome > 1260)
cout<<temp.ID<<" "<<-1<<endl;
else
cout<<temp.ID<<" "<<temp.waitTime<<endl;
}
public:
queue<clients> queueClients;
vector<vector<int>> seatInfo;
};
int main()
{
CanTing canting;
return 0;
}