HDU - 6000 Wash 贪心+优先队列

HDU - 6000 Wash 贪心+优先队列

【vj链接】


题目

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! 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

题目大意与解题思路

T ;//T组数据
L N M ;//L件衣服,N个洗衣机,M个烘干机
w1 w2 w3 ……;//N个洗衣机各自洗一件衣服所用的时间
d1 d2 d3 ……;//M个烘干机各自洗一件衣服所用的时间

一开始所有衣服都是待洗的,衣服之间没有区别,先洗后烘干。求处理完所有衣服的最早时间。

1、将洗衣机按照洗完下一件衣服的时间来排序,也就是洗完第一件衣服用w[i],第二件是2 * w[i]……
通过优先队列得到每件衣服最早洗完的时间。
2、对于烘干机来说,要使结束时间最早就要让最后一件衣服尽量早烘干,也就是每件衣服的烘干时间取max。
考虑两件衣服,洗完时间分别为w1<w2,两台烘干机分别为d1<d2,显然不可能让w2匹配d2,也就是说最后洗完的应该配最快的烘干机。
关于烘干机重复使用,
当w2-w1<d时,w1+2 * d,w2+d也就是让w1等待是比较好的;
当w2-w1>d时,虽然按照上面的原则会让w1等待时间变长,但是因为w1+d<w2,所以w1+2 * d<w2+d,也就是说这种情况下w2+d是最后洗完的衣服,w1+2 * d对答案没有影响。


AC代码

#include <bits/stdc++.h>
#define LL long long
using namespace std;

const int maxn = 1e6+7;
const LL mod = 998244353;
const int INF=1e9+2e7;

struct node
{
    LL t,tim;
    friend bool operator<(node a,node b)
    {
        return a.tim>b.tim;
    }
}f,ne;
LL a[maxn];
priority_queue<node> q1,q2;
int main()
{
    int l,n,m,i,j,k,x,y,len,cnt=0;
    LL ans;
    int T,Case=0;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&l,&n,&m);
        while(!q1.empty()) q1.pop();
        while(!q2.empty()) q2.pop();
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&f.t);
            f.tim=f.t;
            q1.push(f);
        }
        for(i=1;i<=m;i++)
        {
            scanf("%lld",&f.t);
            f.tim=f.t;
            q2.push(f);
        }
        for(i=1;i<=l;i++)
        {
            f=q1.top();
            q1.pop();
            a[i]=f.tim;
            f.tim+=f.t;
            q1.push(f);
        }
        ans=0;
        for(i=l;i>=1;i--)
        {
            f=q2.top();
            q2.pop();
            ans=max(ans,a[i]+f.tim);
            f.tim+=f.t;
            q2.push(f);
        }
        printf("Case #%d: %lld\n",++Case,ans);
    }
    return 0;
}

/**
2
2 2 1
10 11
5
2 2 1
10 16
5
**/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值