1017. Queueing at Bank (25)

#define  _CRT_SECURE_NO_WARNINGS
#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<string>  
#include<vector>  
#include<map>  
#include<iostream>  
#include<queue>  
#include<algorithm>  


using namespace std;
struct Window
{
int endtime; 
Window()
{
endtime = 28800;  
}
};
struct Customer
{
int arrTime, dealTime, waitTime;
};
int FindMinTime(Window *win,int K)
{
int Mark = 0, Min = 99999;
for (int i = 0; i < K; i++)
{
if (win[i].endtime < Min)
{
Min = win[i].endtime;
Mark = i;
}
}
return Mark;
}
bool cmp(Customer a,Customer b)
{
return a.arrTime < b.arrTime;
}
int main()
{  
int N, K;
cin >> N >> K;
Window *win = new Window[K];
Customer *cust = new Customer[N];
for (int i = 0; i < N; i++)
{
if (i == 5)
{
int ccc = 0;
}
int a=0, b=0, c=0;
scanf("%d:%d:%d %d",&a,&b,&c,&cust[i].dealTime);
cust[i].dealTime *= 60;
cust[i].arrTime = a * 3600 + b * 60 + c; 
if (cust[i].arrTime > 61200)
{
i -- ; N--;
}
}
sort(cust, cust + N,cmp);
float sum = 0;
for (int i = 0; i < N; i++)
{
int min = FindMinTime(win, K);
if (cust[i].arrTime < win[min].endtime)
{
cust[i].waitTime = win[min].endtime - cust[i].arrTime;
win[min].endtime = cust[i].dealTime + win[min].endtime;
}
else
{
cust[i].waitTime = 0;
win[min].endtime = cust[i].dealTime + cust[i].arrTime;

sum += cust[i].waitTime;
}
sum /= float(N);
printf("%.1f", sum/60.0);
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值