zoukankan      html  css  js  c++  java
  • 【codeforces 452D】Washer, Dryer, Folder

    【题目链接】:http://codeforces.com/problemset/problem/452/D

    【题意】

    洗衣服有3个步骤,洗,干,叠;
    有对应的3种洗衣机,分别有n1,n2,n3台,然后每一种洗衣机,一台完成对应的步骤所需的时间为t1,t2,t3;
    已知你有k件衣服要洗;
    问你最少需要洗多长时间;

    【题解】

    用3个优先队列;
    维护每一种洗衣机,在何时是处于空闲状态的;(即什么时候会有一件衣服操作完);
    每次将时间跳转到;
    min{q1.top(),q2.top(),q3.top()};
    然后将操作完的衣服放入下一步骤;
    然后将正在等待操作的衣服;如果能放入对应的洗衣机,就放入;

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0),cin.tie(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 110;
    const int INF = 0x3f3f3f3f;
    
    int k,n1,n2,n3,t1,t2,t3,ans;
    int w1,w2,w3;
    priority_queue <int,vector<int>,greater<int>> q1,q2,q3;
    
    int main(){
        //Open();
        Close();//scanf,puts,printf not use
        //init??????
        cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
        w1 = k;
        q1.push(INF),q2.push(INF),q3.push(INF);
        while (w1 || w2 || w3 || (int) q1.size()>1 || (int) q2.size()>1 || (int) q3.size()>1){
            ans = min(q1.top(),min(q2.top(),q3.top()));
            if (ans==INF) ans = 0;
            while (q1.top()<=ans){
                q1.pop();
                w2++;
            }
            while (q2.top()<=ans){
                q2.pop();
                w3++;
            }
            while (q3.top()<=ans){
                q3.pop();
            }
            while (w1 && (int) q1.size()<=n1){
                w1--;
                q1.push(ans+t1);
            }
            while (w2 && (int) q2.size()<=n2){
                w2--;
                q2.push(ans+t2);
            }
            while (w3 && (int) q3.size()<=n3){
                w3--;
                q3.push(ans+t3);
            }
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    第十三周助教小结
    记事本
    第十二周助教小结
    与周老师会谈之后的感想
    第十一周总结
    第十周助教总结
    听周筠老师一席话,受益匪浅
    2020软件工程作业04
    2020软件工程作业02
    2020软件工程作业01
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626292.html
Copyright © 2011-2022 走看看