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

来一发 2017年第二A:题意:L堆衣服,N台洗衣机,M台脱水机,给出每台机器的每次工作的时间 Wi,Di。一台机器一次只能给一堆衣服工作,求洗完衣服最少需要多少时间。

毫不犹豫的来一发 最大加最小(最小洗完时间加最大的脱水时间)先分别计算每堆衣服的最少洗完时间,然后再用最小洗完时间加上需要最大的脱水时间。

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define siz 1000005
typedef long long ll;
using namespace std;
struct node
{
    ll cot;
    int id;
    bool operator <(const node &a) const
    {
        return a.cot<cot;
    }
};
ll a[siz],b[siz],d[siz];
int L,N,M;
ll ans;
void solve()
{
    node V,U;
    ll time;
    priority_queue<node>Q1,Q2;
    for(int i=1; i<=N; i++)
    {
        U.cot =a[i], U.id =i;
        Q1.push(U);
    }
    for(int i=1; i<=M; i++)
    {
        U.cot =b[i], U.id =i;
        Q2.push(U);
    }
    for(int i=1; i<=L; i++) //洗衣服
    {
        V = Q1.top();
        Q1.pop();
        time = V.cot;
        U.cot=V.cot+a[ V.id ], U.id =V.id;
        Q1.push(U);
        d[i] = time;
    }
    for(int i=L; i>=1; i--)  //脱水
    {
        V =Q2.top();
        Q2.pop();
        time = V.cot;
        U.cot=V.cot+b[ V.id ], U.id =V.id;
        Q2.push(U);
        ans =max(ans,time+d[i]);
    }
    return;
}
int main()
{
    int T;
    cin>>T;
    for(int t=1; t<=T; t++)
    {
        scanf("%d %d %d",&L,&N,&M);
        for(int i=1; i<=N; i++) scanf("%I64d",&a[i]);
        for(int i=1; i<=M; i++) scanf("%I64d",&b[i]);
        ans  = -1;
        solve();
        printf("Case #%d: %I64d\n",t,ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值