假设银行有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
输出样例:
15.1 35 67
4 5 1
头秃了都没想出来除了时间轴走以外的办法,二维数组爆理论上不科学...
#include<cstdio>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define EPS 1e-5
typedef long long ll;
const int maxn = 1003;
int n;//顾客
int num;//窗口
int pos_vip;
class Window
{
public:
int serve;
bool VIP;
Window()
{
serve = 0;
VIP = 0;
}
void change()
{
VIP = 1;
}
} win[13];
class Person
{
public:
int come;
int cost;
bool VIP;
bool vis;
int wait;
int leave;
Person()
{
come = cost = wait = leave = 0;
VIP = vis = 0;
}
void cun(int a,int b,bool c)
{
come = a;
cost = b;
VIP = c;
}
} people[maxn];
bool dp[13][maxn*62];
int pingjun=0,zuichang=0,zuihou=0;
void tongji()
{
for(int i=0;i<n;i++)
{
pingjun += people[i].wait;
zuichang = max(zuichang,people[i].wait);
zuihou = max(zuihou,people[i].leave);
}
cout<<fixed<<setprecision(1)<<pingjun*1.0/n<<" ";
cout<<zuichang<<" "<<zuihou<<endl;
for(int i=0;i<num;i++)
{
if(i == 0)
cout<<win[i].serve;
else cout<<" "<<win[i].serve;
}
cout<<endl;
}
int main()
{
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
// memset(dp,0,sizeof(dp));
cin>>n;
for(int i=0; i<n; i++)
{
int a,b;
bool c;
cin>>a>>b>>c;
if(b >60)
b = 60;
people[i].cun(a,b,c);
}
cin>>num>>pos_vip;
int pos = 0;
Person a;
for(int time=0; pos<n; time++)
{
if(dp[pos_vip][time] == 0)//如果vip窗口有空
{
for(int i=0; i<n; i++)//找到能办业务的
{
if(people[i].come > time)break;
if(people[i].vis || !people[i].VIP)//访问过或者不是vip
continue;
people[i].vis = 1;
people[i].wait = max(time - people[i].come,0);
people[i].leave = time + people[i].cost;
win[pos_vip].serve++;
for(int j=time; j<time+people[i].cost; j++)
dp[pos_vip][j] = 1;
++pos;
break;
}
}
for(int k=0; k<num; k++)//遍历窗口
{
if(dp[k][time] == 0)//有空
{
for(int i=0; i<n; i++)//找客人
{
if(people[i].come > time)break;
if(people[i].vis)continue;
people[i].vis = 1;
people[i].wait = max(time - people[i].come,0);
people[i].leave = time + people[i].cost;
win[k].serve++;
for(int j=time; j<time+people[i].cost; j++)
dp[k][j] = 1;
++pos;
break;
}
}
}
}
tongji();
return 0;
}