#include<bits/stdc++.h>
using namespace std;
struct Customers {
int arrived;
int need;
int wait;
};
int counter_time[10] = {0};
int counter_serve[10] = {0};
int main() {
vector<Customers> customers;//用队列,数组也可以
int n, k;
cin>>n;//顾客数
for(int i = 0; i < n; i++) {
Customers t;
cin>>t.arrived>>t.need;
if(t.need>60) t.need = 60;
customers.push_back(t);
}
cin>>k;//窗口数
for(int i = 0; i < n; i++)
{
int choose = 0;
for (int j = 0; j < k; j++)
{
if (counter_time[choose] > counter_time[j])//寻找最小时间
choose = j;
if (customers[i].arrived >= counter_time[choose])
break;
}
if (customers[i].arrived >= counter_time[choose])
{
counter_time[choose] = customers[i].arrived + customers[i].need;
customers[i].wait = 0;
}
else
{
customers[i].wait = counter_time[choose] - customers[i].arrived;
counter_time[choose] += customers[i].need;//更新窗口等待时间
}
counter_serve[choose]++;//窗口服务总人数
}
double sum = 0;
double longest_wait = 0;
double longest_complete = 0;
for(int i = 0; i < n; i++) {
sum += customers[i].wait;
if(customers[i].wait > longest_wait) longest_wait = customers[i].wait;
}
for(int i = 0; i < k; i++) {
if(counter_time[i] > longest_complete) longest_complete = counter_time[i];
}
printf("%.1lf ",sum/n);
cout<<longest_wait<<" "<<longest_complete<<endl;
for(int i = 0; i < k; i++) {
if(i != 0) cout<<" ";
cout<<counter_serve[i];
}
}
银行排队问题之单队列多窗口服务 (25 分)
最新推荐文章于 2023-11-23 19:56:31 发布