7-5 银行排队问题之单队列多窗口加VIP服务

#include<iostream>
#include<cstdio>
using namespace std;
int n,t[1005],p[1005],cost[1005],k,ans0,ans[1005],mx1,mx2,vip,next1[1005],nw,w[1005];
bool isvip[1005],solve[1005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>p[i]>>isvip[i];
		p[i]=min(p[i],60);
		if(isvip[i])
		{
			next1[nw]=i;
			nw=i;
		}
	}
	nw=0;
	cin>>k>>vip;
	int sl=0,nx=1;
	while(sl<n)
	{
		sl++;
		int ed=1e9,num;
		for(int i=0;i<k;i++)
		{
			if(w[i]<ed&&ed>t[nx])
			{
				ed=w[i];
				num=i;
			}
		}
		if(num==vip)
		{
			if(next1[nw]&&t[next1[nw]]<=ed)
			{
				nw=next1[nw];
				cost[nw]=ed-t[nw];
				w[num]=ed+p[nw];
				solve[nw]=1;
//				cout<<1<<endl;
//				cout<<nw<<' '<<num<<endl;
			}
			else{
				cost[nx]=max(0,ed-t[nx]);
				w[num]=t[nx]+cost[nx]+p[nx];
				solve[nx]=1;
//				cout<<2<<endl;
//				cout<<nx<<' '<<num<<endl;
			}
			ans[num]++;
		}
		else{
			if(isvip[nx]&&(w[vip]<=ed||w[vip]<=t[nx])) num=vip;
			cost[nx]=max(0,ed-t[nx]);
			w[num]=t[nx]+cost[nx]+p[nx];
			solve[nx]=1;
			ans[num]++;	
//			cout<<3<<endl;	
//			cout<<nx<<' '<<num<<endl;	
		}
		while(solve[nx])
		nx++;
		while(next1[nw]&&solve[next1[nw]])
		nw=next1[nw];
	}
	for(int i=1;i<=n;i++)
	{
		ans0+=cost[i];
		mx1=max(mx1,cost[i]);
	}
	for(int i=0;i<k;i++)
		mx2=max(mx2,w[i]);
	printf("%.1lf %d %d\n",(double)ans0/n,mx1,mx2);
	cout<<ans[0];
	for(int i=1;i<k;i++)
	cout<<' '<<ans[i];
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哈希表扁豆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值