• CF452D Washer, Dryer, Folder


    题目描述

    You have kk pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n_{1}n1 washing machines, n_{2}n2 drying machines and n_{3}n3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it before it is dried. Moreover, after a piece of laundry is washed, it needs to be immediately moved into a drying machine, and after it is dried, it needs to be immediately moved into a folding machine.

    It takes t_{1}t1 minutes to wash one piece of laundry in a washing machine, t_{2}t2 minutes to dry it in a drying machine, and t_{3}t3 minutes to fold it in a folding machine. Find the smallest number of minutes that is enough to wash, dry and fold all the laundry you have.

    输入格式

    The only line of the input contains seven integers: k,n_{1},n_{2},n_{3},t_{1},t_{2},t_{3}k,n1,n2,n3,t1,t2,t3(1<=k<=10^{4}; 1<=n_{1},n_{2},n_{3},t_{1},t_{2},t_{3}<=1000) .

    输出格式

    Print one integer — smallest number of minutes to do all your laundry.

    题意翻译

    你有k件待洗的脏衣服和n1个洗衣机,n2个烘干机和n3个熨斗。每个机器同时只能处理一件衣服,分别花费t1,t2,t3时间。你必须将一件洗好的衣服立即烘干,烘干完毕后立即熨烫,不能颠倒顺序也不能在两阶段中间有间隔。

    输入一行7个数为k,n1,n2,n3,t1,t2,t3。输出一个数字,为全部熨烫完衣服的最短时间。

    1<=k<=10^4,1<=n,t<=10^3。

    输入输出样例

    输入 #1
    1 1 1 1 5 5 5
    
    输出 #1
    15
    
    输入 #2
    8 4 3 2 10 5 2
    
    输出 #2
    32
    

    说明/提示

    In the first example there's one instance of each machine, each taking 5 minutes to complete. You have only one piece of laundry, so it takes 15 minutes to process it.

    In the second example you start washing first two pieces at moment 00 . If you start the third piece of laundry immediately, then by the time it is dried, there will be no folding machine available, so you have to wait, and start washing third piece at moment 22 . Similarly, you can't start washing next piece until moment 55 , since otherwise there will be no dryer available, when it is washed. Start time for each of the eight pieces of laundry is 0,0,2,5,10,10,120,0,2,5,10,10,12 and 1515 minutes respectively. The last piece of laundry will be ready after 15+10+5+2=3215+10+5+2=32 minutes.

    用3个优先队列;

    维护每一种洗衣机,在何时是处于空闲状态的;(即什么时候会有一件衣服操作完);

    每次将时间跳转到;

    min{q1.top(),q2.top(),q3.top()};

    然后将操作完的衣服放入下一步骤;

    然后将正在等待操作的衣服;如果能放入对应的洗衣机,就放入;

    #include<cstdio>
    #include<queue>
    using namespace std;
    #define rep(i,a,n) for(register int i=a;i<=n;++i)
    #define mi min(n1,min(n2,n3))
    #define ma max(q1,max(q2,q3)) 
    using namespace std;
    deque<int>w,d,f;
    int k,n1,n2,n3,t1,t2,t3,q1,q2,q3,mo;
    
    inline int read(){
        int s=0,w=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-'){
                w=-1;
            }
            ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            s=s*10+ch-'0';
            ch=getchar();
        }
        return s*w;
    }
    
    
    int main()
    {
        k=read();
        n1=read();
        n2=read();
        n3=read();
        t1=read();
        t2=read();
        t3=read();
        rep(i,1,mi)
        {
            w.push_back(t1);
            d.push_back(t1+t2);
            f.push_back(t1+t2+t3);
        }
        rep(i,mi+1,k)
        {
            q1=w.at(0);
            q2=d.at(0)-t1;
            q3=f.at(0)-t1-t2;
            if(w.size()<n1)
            q1=0;
            if(d.size()<n2)
            q2=0;
            if(f.size()<n3)
            q3=0;
            mo=ma;
            if(!(w.size()<n1))
            w.pop_front();
            if(!(d.size()<n2))
            d.pop_front();
            if(!(f.size()<n3))
            f.pop_front();
            w.push_back(mo+t1);
            d.push_back(mo+t1+t2);
            f.push_back(mo+t1+t2+t3);
        }
        printf("%d ",f.back());
        return 0;
    }
  • 相关阅读:
    PHP中防止SQL注入的方法
    SQLmap超详细文档和实例演示
    Spring Cloud 个人心得 理论
    Spring注解说明
    git各角色权限描述
    jenkins调用tomcat重启命令 && tomcat重启脚本
    nginx1.5 升级到1.14
    发布项目
    spring boot 多线程
    Jmeter测试http请求
  • 原文地址:https://www.cnblogs.com/hrj1/p/11669080.html
Copyright © 2020-2023  润新知