题目描述
假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙。当有窗口空闲时,下一位顾客即去该窗口处理事务。当有多个窗口可选择时,假设顾客总是选择编号最小的窗口。
有些银行会给VIP客户以各种优惠服务,例如专门开辟VIP窗口。为了最大限度地利用资源,VIP窗口的服务机制定义为:
当队列中没有VIP客户时,该窗口为普通顾客服务;
当该窗口空闲并且队列中有VIP客户在等待时,排在最前面的VIP客户享受该窗口的服务。
同时,当轮到某VIP客户出列时,若VIP窗口非空,该客户可以选择空闲的普通窗口;否则一定选择VIP窗口。
本题要求输出前来等待服务的N位顾客的平均等待时间、最长等待时间、最后完成时间,并且统计每个窗口服务了多少名顾客。
输入
输入第1行给出正整数N(≤1000),为顾客总人数;随后N行,每行给出一位顾客的到达时间T、
事务处理时间P和是否VIP的标志(1是VIP,0则不是),并且假设输入数据已经按到达时间先后排好了顺序;
最后一行给出正整数K(≤10)—— 为开设的营业窗口数,以及VIP窗口的编号(从0到K-1)。
这里假设每位顾客事务被处理的最长时间为60分钟。
输出
在第一行中输出平均等待时间(输出到小数点后1位)、最长等待时间、最后完成时间,之间用1个空格分隔,行末不能有多余空格。
输入输出样例
输入样例1 <-复制
10
0 20 0
0 20 0
1 68 1
1 12 1
2 15 0
2 10 0
3 15 1
10 12 1
30 15 0
62 5 1
3 1
输出样例1
15.1 35 67
4 5 1
AC代码
#include<iostream>
#include<iomanip>
#include<queue>
using namespace std;
struct customer
{
int dao, hao, vip;
customer(int t, int p,int pan)
{
dao = t; hao = p; vip = pan;
}
};
struct chuan
{
int fuwu = 0;
int shen = 0;
};
int kong(chuan* kou, int k)
{
int i;
for (i = 0; i < k; i++)
{
if (kou[i].shen == 0)
return i;
}
return -1;
}
void jian(chuan* kou, int k)
{
int i;
for (i = 0; i < k; i++)
{
if (kou[i].shen != 0)
kou[i].shen--;
}
}
void show(chuan* kou, int k)
{
int i;
for (i = 0; i < k; i++)
{
cout << kou[i].fuwu;
if (i != k - 1)
cout << " ";
else
cout << endl;
}
}
int jieshu(chuan* kou, int k)
{
int i;
for (i = 0; i < k; i++)
{
if (kou[i].shen != 0)
return 0;
}
return 1;
}
int zvip(queue<customer> s,int fen)
{
int i = 0;
while (!s.empty())
{
if (s.front().vip == 1&&fen>=s.front().dao)
return i;
i++;
s.pop();
}
return -1;
}
int main()
{
int fen = 0;
int n, t, p, k;
queue <customer> q;
queue <int> dengdui;
int i;
int deng = 0;
int pan;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> t >> p >> pan;
customer guke(t, p,pan);
q.push(guke);
}
cin >> k;
int vkou;
cin >> vkou;
chuan* kou = new chuan[k];
while (!q.empty())
{
if (kong(kou, k) == -1)
{
fen++;
jian(kou, k);
continue;
}
while (kong(kou, k) != -1 && !q.empty())
{
int o = kong(kou, k);
customer oo = q.front();
if (zvip(q,fen) != -1&& kou[vkou].shen == 0)
{
int wei = zvip(q,fen);
queue<customer>ss;
for (i = 0; i < wei; i++)
{
ss.push(q.front());
q.pop();
}
customer temp = q.front();
q.pop();
while (!q.empty())
{
ss.push(q.front());
q.pop();
}
q.push(temp);
while (!ss.empty())
{
q.push(ss.front());
ss.pop();
}
oo = q.front();
}
if (oo.dao > fen)
{
break;
}
if (oo.vip == 1 && kou[vkou].shen == 0)
o = vkou;
q.pop();
kou[o].fuwu++;
if (oo.hao <= 60)
kou[o].shen = oo.hao;
else
kou[o].shen = 60;
if (fen - oo.dao)
{
dengdui.push(fen - oo.dao);
}
}
fen++;
jian(kou, k);
}
while (!jieshu(kou, k))
{
fen++;
jian(kou, k);
}
double all = 0;
int max = 0;
while (!dengdui.empty())
{
all += dengdui.front();
if (max < dengdui.front())
max = dengdui.front();
dengdui.pop();
}
double ren = n;
double average = all / ren;
cout << fixed << setprecision(1) << average << " " << max << " " << fen << endl;
show(kou, k);
}
(by 归忆)