美文网首页PAT
B1017 Queueing at Bank (排队模拟)

B1017 Queueing at Bank (排队模拟)

作者: Tsukinousag | 来源:发表于2020-01-19 20:31 被阅读0次

    B1017 Queueing at Bank (25分)

    • Notice that the bank opens from 08:00 to 17:00. 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.

    这家银行只要你在17:01之前到了你就能等到你的服务,全部服务完再关门,所以挑选窗口的时候不用去考虑时间到17:01就break。(最后一个测试点2分)

    还有一个注意点tolminute/60.0/tolnum,tolnum为0的情况别忽略

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string.h>
    #include <cmath>
    #include <math.h>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <stack>
    using namespace std;
    typedef long long ll;
    const int MAX=10005;
    const int INF=0x3f3f3f3f;
    const int mod=1000000007;
    struct nodeperson
    {
        int arrive,serve,time;
    };
    struct nodetable
    {
        int endtime;
    };
    vector<nodeperson>person;
    vector<nodetable>table;
    bool cmp(nodeperson a,nodeperson b)
    {
        return a.arrive<b.arrive;
    }
    void deal(int p,int t)
    {
        if(person[p].arrive<=table[t].endtime)
        {
            person[p].serve=table[t].endtime;
        }
        else
            person[p].serve=person[p].arrive;
        table[t].endtime=person[p].serve+person[p].time;
    
    }
    int main()
    {
        int n,m,tolnum=0;
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        {
            int hour,minute,second,dotime;
            scanf("%d:%d:%d %d",&hour,&minute,&second,&dotime);
            nodeperson tempperson;
            tempperson.arrive=hour*3600+minute*60+second;
            //tempperson.serve=3600*17+1;//不用设置初始服务时间
            if(tempperson.arrive>17*3600)
                continue;
            tempperson.time=dotime*60;
            person.push_back(tempperson);
            tolnum++;
        }
        for(int i=0;i<m;i++)
        {
            nodetable temptable;
            temptable.endtime=8*3600;
            table.push_back(temptable);
        }
        sort(person.begin(),person.end(),cmp);
        for(int i=0;i<person.size();i++)
        {
            int index,Min=INF;
            for(int j=0;j<table.size();j++)
            {
                if(Min>table[j].endtime)
                {
                    Min=table[j].endtime;
                    index=j;
                }
            }
            deal(i,index);
        }
        double tolminute=0;
        for(int i=0;i<person.size();i++)
        {
            tolminute+=(double)(person[i].serve-person[i].arrive);
        }
        if(tolnum==0)
        {
            printf("0.0\n");
        }
        else
        printf("%.1f\n",tolminute/60.0/tolnum);
        return 0;
    }
    

    相关文章

      网友评论

        本文标题:B1017 Queueing at Bank (排队模拟)

        本文链接:https://www.haomeiwen.com/subject/kmcdzctx.html