pat 1017. Queueing at Bank (25)
queue模拟题
注意题目所求得是平均等待时间
还有 如果顾客在8点之前到达,需等到8点才能得到服务
顾客如果在17点之后到达,银行不为其提供服务,但一旦到达时间在17点之前,即使结束时间在17点之后 ,银行也要为其服务
[cpp]
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
#define S 8*60*60
#define E 17*60*60
#define INF 0x7fffffff
struct node
{
int time;
int process;
int begin;
int leave;
};
int max(int a,int b)
{
return a>b?a:b;
}
int cmp(struct node a,struct node b)
{
return a.time<b.time;
}
int main()
{
int n,k,i,h,m,s,j,min,index,t;
while(scanf("%d%d",&n,&k)!=EOF)
{
vector<struct node >cus(n);
//vector<queue<int> >winque(k);
vector<int>now(k,S);
for(i=0;i<n;i++)
{
scanf("%d:%d:%d%d",&h,&m,&s,&cus[i].process);
cus[i].process*=60;
cus[i].time=(h*60+m)*60+s;
}
sort(cus.begin(),cus.end(),cmp);
for(i=0;i<n;i++)
{
min=INF;
for(j=0;j<k;j++)
if(min>now[j])
{
min=now[j];
index=j;
}
cus[i].begin=max(now[index],cus[i].time);
cus[i].leave=cus[i].begin+cus[i].process;
now[index]=cus[i].leave;
}
t=0;
s=n;
for(i=0;i<n;i++)
{
//printf("%d %d %d %d\n",i,cus[i].time,cus[i].begin,cus[i].leave);
if(cus[i].time<=E)// Anyone arrives early will have to wait in line till 08:00,
//and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.
//任何人只要在五点之前到达 银行就要为其服务
{
t+=cus[i].begin-cus[i].time;
//printf("%d\n",t);
}
else
s--;
}
if(s)printf("%.1lf\n",t/60.0/s);//求 等待 时间的平均值
else
printf("0.0\n");
}
return 0;
}
补充:软件开发 , C++ ,