• 复杂模拟 | 1017 模拟N个顾客M个柜台进行排队


    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 1010
    #define MAX (1<<30)+1
    #define V vector<int>
    
    using namespace std;
    
    struct Customer{
        int comeTime;
        int serveTime;
        Customer(int c,int s):comeTime(c),serveTime(s){
        }
    };
    
    bool cmp(Customer a,Customer b){
        return a.comeTime<b.comeTime;
    }
    
    int processTime(int H,int M,int S){
        return H*3600+M*60+S;
    }
    
    int windowEnd[1000];//每个窗口的结束时间 
    
    int main(){
    //    freopen("1017.txt","r",stdin);
        int N,M,i,j,hh,mm,ss,p;
        I("%d %d",&N,&M);
        int startTime=processTime(8,0,0);
        int endTime=processTime(17,0,0);
        vector<Customer> C;
        FF(i,M) windowEnd[i]=startTime;    //初始化每个窗口的开始时间 
        while(N--){
            I("%d:%d:%d %d",&hh,&mm,&ss,&p);
            int thisTime=processTime(hh,mm,ss);
            if(thisTime>endTime) continue;
            p*=60;
            p=min(p,3600);        //处理排队超时 
            C.push_back(Customer(thisTime,p));
        }
        sort(C.begin(),C.end(),cmp);
        int wait=0;
        //对于每一个顾客进行处理
        FF(i,C.size()){
            //选择一个最早结束的
            int minTime=MAX,mI;
            FF(j,M) {
                if(windowEnd[j]<minTime){
                    minTime=windowEnd[j];
                    mI=j;
                }
            }
            if(windowEnd[mI]>C[i].comeTime){    //顾客来早了,需要等待 
                wait+=windowEnd[mI]-C[i].comeTime;
                windowEnd[mI]+=C[i].serveTime;
            }else{        //顾客不用等待 
                windowEnd[mI]=C[i].comeTime+C[i].serveTime;
            }
        }
        O("%.1f
    ",wait/60.0/C.size());
        return 0;
    }
  • 相关阅读:
    CF666E. Forensic Examination
    bzoj1396 识别子串
    bzoj2839 集合计数
    unknown
    Hibernate中一级缓存和二级缓存
    亲, 我们来再重申一遍"=="和"equals的区别
    BigDecimal类
    序列化详解
    利用简单的参数传递来实现单条查询的easyui-datagrid
    Oracl 动态执行表不可访问,本会话的自动统计被禁止
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8574365.html
Copyright © 2020-2023  润新知