• 【HDU 6000】Wash(贪心)


    Problem Description


    Mr.Panda is about to engage in his favourite activity doing laundry! He’s brought L indistinguishable loads of laundry to his local laundromat, which has N washing machines and M dryers.The ith washing machine takes Wi minutes to wash one load of laundry, and the ith dryer takes Di minutes to dry a load of laundry.
    At any point in time, each machine may only be processing at most one load of laundry.
    As one might expect, Panda wants to wash and then dry each of his L loads of laundry. Each load of laundry will go through the following steps in order:

    1. A non-negative amount of time after Panda arrives at the laundromat, Panda places the load in an unoccupied washing machine i.
    2. Wi minutes later, he removes the load from the washing machine, placing it in a temporary holding basket (which has unlimited space)
    3. A non-negative amount of time later, he places the load in an unoccupied dryer j
    4. Dj minutes later, he removes the load from the dryer Panda can instantaneously add laundry to or remove laundry from a machine. Help Panda minimize the amount of time (in minutes after he arrives at the laundromat) after which he can be done washing and drying all L loads of laundry!

    Input


    The first line of the input gives the number of test cases, T.
    T test cases follow. Each test case consists of three lines. The first line contains three integer L, N, and M.
    The second line contains N integers W1,W2,...,WN representing the wash time of each wash machine.
    The third line contains M integers D1,D2,...,DM representing the dry time of each dryer.

    Output


    For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the minimum time it will take Panda to finish his laundry.
    limits
    ∙1≤T≤100.
    ∙1≤L≤106.
    ∙1≤N,M≤105.
    ∙1≤Wi,Di≤109.

    Sample Input

    2
    1 1 1
    1200
    34
    2 3 2
    100 10 1
    10 10
    

    Sample Output

    Case #1: 1234
    Case #2: 12
    

    Source

    2016 CCPC-Final

    题解


    先考虑洗衣服的过程,对于每一件衣服,我们取当前已耗时间最小的洗衣机,这样可以的到每一件衣服的最早被清洗完成的时间a[i]。再考虑烘干衣服的过程,对于每一件已经被清洗的衣服,我们取当前已耗时间最小的烘干机,这样可以得到每件衣服加工完成的时间,取最大的即可。

    参考代码

    #include <map>
    #include <queue>
    #include <cmath>
    #include <cstdio>
    #include <complex>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #define ll long long
    #define inf 1000000000
    #define PI acos(-1)
    #define REP(i,x,n) for(int i=x;i<=n;i++)
    #define DEP(i,n,x) for(int i=n;i>=x;i--)
    #define mem(a,x) memset(a,x,sizeof(a))
    using namespace std;
    ll read(){
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    void Out(ll a){
        if(a<0) putchar('-'),a=-a;
        if(a>=10) Out(a/10);
        putchar(a%10+'0');
    }
    const int N=1e6+10;
    struct node{
        ll x,y;
        bool operator < (const node &an) const{
            return y>an.y;
        }
    };
    ll a[N];
    int main(){
        int T=read();
        REP(i,1,T){
           int l=read(),n=read(),m=read();
           int d;
           priority_queue<node>que;
           REP(i,1,n){
              d=read();
              que.push(node{d,d});
           }
           node tmp;
           REP(i,1,l){
              tmp=que.top();
              que.pop();
              a[i]=tmp.y;
              que.push(node{tmp.x,tmp.x+tmp.y});
           }
           while(!que.empty()) que.pop();
           REP(i,1,m){
              d=read();
              que.push(node{d,d});
           }
           ll ans=0;
           DEP(i,l,1){
              tmp=que.top();
              que.pop();
              ans=max(ans,tmp.y+a[i]);
              que.push(node{tmp.x,tmp.y+tmp.x});
           }
           printf("Case #%d: %lld
    ",i,ans);
        }
        return 0;
    }
    
  • 相关阅读:
    Windows7安装SQL Server 2008图解
    【Android病毒分析报告】
    linux source命令学习
    SQL学习笔记——SQL初入门,Ubuntu下MySQL的安装
    挂断电话的实现(即类似于电话号码黑名单)
    35+雪花Logos设计灵感
    jdk8预览
    PL/SQL --> 动态SQL调用包中函数或过程
    VMware 彻底删除虚拟机操作系统的方法
    Ubuntu 16.04 LTS: apt-get update 失败处理 Aborted (core dumped)
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/7218589.html
Copyright © 2020-2023  润新知