1017 Queueing at Bank (25)

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 10010;
struct customer {
    int arriveTime;
    int processTime;
} Customer[MAXN];
struct window {
    int startEmptyTime = 8 * 3600;
} Window[MAXN];
bool cmp1(customer a, customer b) {
    return a.arriveTime < b.arriveTime;
}
bool cmp2(window a, window b) {
    return a.startEmptyTime < b.startEmptyTime;
}
int main() {
    int N, K;
    scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++) {
        int t1, t2, t3;
        scanf("%d:%d:%d",&t1,&t2,&t3);
        Customer[i].arriveTime = t1 * 3600 + t2 * 60 + t3;  //秒计
        int currentProcessTime;
        scanf("%d",¤tProcessTime);
        Customer[i].processTime = currentProcessTime * 60;
    }
    sort(Customer,Customer+N,cmp1);
    int cnt = 0;
    double TotalaitTime = 0.0;
    for(int i=0; i<N; i++) {
        if(Customer[i].arriveTime <= 17 * 3600) {  //把下班之前已经受理的业务办完再下班
            sort(Window,Window+K,cmp2);  //是按照最空,而不是按照窗口的顺序
            if(Window[0].startEmptyTime - Customer[i].arriveTime > 0) {  //需要等待 
            	TotalaitTime += Window[0].startEmptyTime - Customer[i].arriveTime;
				Window[0].startEmptyTime += Customer[i].processTime;	
			} else {  //无要等待 
				Window[0].startEmptyTime += Customer[i].processTime + (Customer[i].arriveTime - Window[0].startEmptyTime);	
			}
            cnt ++;
        }
    }
    printf("%0.1lf\n",TotalaitTime / cnt / 60);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值