zoukankan      html  css  js  c++  java
  • 复杂模拟 | 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;
    }
  • 相关阅读:
    zabbix监控nginx的性能
    常用iptables命令
    shell脚本小示例
    打印菜单脚本
    ping主机脚本
    Linux网络配置脚本
    多磁盘自动分区自动挂载脚本
    深入js系列-类型(null)
    深入js系列-类型(开篇)
    first-child、last-child误解
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8574365.html
Copyright © 2011-2022 走看看