HDU 6000 Wash (优先队列-贪心)

24 篇文章 0 订阅
17 篇文章 0 订阅

题意:

你有L件衣服, 有n 个洗衣机, m 个烘干机, 告诉你每个洗衣机的洗衣服的时间,和每个烘干机的烘干时间, 每个机器 一个时间段只能处理一件衣服,问洗完这L 件衣服最短时间是多少?

思路:

贪心。

第一步很好想,我们先求出每一件衣服最早的洗好的时间。

然后在烘干, 这里因为是最后一件时间尽量少, 因此我们采用最晚的洗好的时间 用第一个烘干机。(最大值加最小值的贪心方式进行贪心)

这样肯定是比正着来(最大值+最大值 要短的)

吐槽:

注意数组大小, 和long long,非法访问内存是可能出现任何错误的。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int ks, T, L, n, m;
typedef long long LL;

const int maxn = 1e6+10;

LL c[maxn];

struct Node{
    LL v, base;
    Node(LL v = 0, LL base = 0):v(v), base(base){}
    bool operator < (const Node& rhs) const {
        return v > rhs.v;
    }
};

priority_queue<Node>q1,q2;
LL x;
int main(){

    scanf("%d",&T);

    while(T--){
        while(!q1.empty()) q1.pop();
        while(!q2.empty()) q2.pop();
        scanf("%d %d %d",&L, &n, &m);
        for (int i = 0; i < n; ++i){

            scanf("%lld",&x);
            q1.push(Node(x,x));
        }

        for (int i = 0; i < m; ++i){

            scanf("%lld",&x);
            q2.push(Node(x,x));
        }

        for (int i = 0; i < L; ++i){
            Node u = q1.top(); q1.pop();
            c[i] = u.v;
            u.v += u.base;
            q1.push(u);
        }
        LL ans = 0;
        for (int i = L-1; i >= 0; --i){
            Node u = q2.top(); q2.pop();
            ans = max(ans, u.v + c[i]);
            u.v += u.base;
            q2.push(u);
        }

        printf("Case #%d: %lld\n",++ks,ans);





    }

    return 0;
}


Wash

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 64000/64000 K (Java/Others)
Total Submission(s): 328    Accepted Submission(s): 78


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


1T100 .
1L106 .
1N,M105 .
1Wi,Di109 .
 

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
 

Recommend
jiangzijing2015   |   We have carefully selected several similar problems for you:   6018  6017  6016  6015  6014 
 

Statistic |  Submit |  Discuss |  Note
Hangzhou Dianzi University Online Judge 3.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值