PAT (Advanced Level) 1017. Queueing at Bank (25)

简单模拟。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
using namespace std;

struct X
{
    long long hh,mm,ss;
    long long len;
    long long st,ml;
}s[10000+10];
int n,k;
long long win[200];

bool cmp(const X&a,const X&b)
{
    return a.st<b.st;
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld:%lld:%lld %lld",&s[i].hh,&s[i].mm,&s[i].ss,&s[i].len);
        s[i].st=s[i].hh*60*60+s[i].mm*60+s[i].ss;
        s[i].len=s[i].len*60;
    }
    sort(s+1,s+1+n,cmp);
    for(int i=1;i<=k;i++) win[i]=8*60*60;
    int i;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        long long Min=999999999999;
        if(s[i].st>17*60*60) break;
        cnt++;
        for(int j=1;j<=k;j++) Min=min(Min,win[j]);
        for(int j=1;j<=k;j++)
        {
            if(win[j]==Min)
            {
                s[i].ml=max(win[j],s[i].st);
                win[j]=s[i].ml+s[i].len;
                break;
            }
        }
    }
    long long sum=0;
    for(int k=1;k<=cnt;k++) sum=sum+s[k].ml-s[k].st;
    if(cnt!=0) printf("%.1f\n",1.0*sum/60/cnt);
    else printf("0.0\n");
    return 0;
}

 

posted @ 2016-05-16 12:54  Fighting_Heart  阅读(135)  评论(0编辑  收藏  举报