HDU6000

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 ithith washing machine takes WiWi minutes to wash one load of laundry, and the ithith 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,…,WNW1,W2,…,WN representing the wash time of each wash machine.
The third line contains M integers D1,D2,…,DMD1,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≤T≤100.
∙1≤L≤106∙1≤L≤106.
∙1≤N,M≤105∙1≤N,M≤105.
∙1≤Wi,Di≤109∙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
这个题目算是一个脑洞题目吧(网上很多人说是贪心)。
1、对L个衣服编号,然后依次洗衣服,用优先级队列你可以计算出最快洗完的时间,以及对应每件衣服洗完的时间。
2、然后我们来思考一下,对于最后洗完的那件衣服(也就是最后一号的衣服),这时候它对应的就是总的洗衣服时间(设为T1max),如果它不用最快的那个烘干机(设为T2min),那么总耗时一定大于(T1max+T2min),但是我们如果用了那个最快的烘干机,就有可能等于(T1max+T2min),对于倒数第二个洗完的衣服也是这样的。
3、所以同样用个优先级队列使最后洗完的衣服,用最快的烘干机。(对倒数第二洗完的衣服,用第二快的烘干机。)这样就在对所有的做法取最大值。

#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
#define ll long long int
struct time{
    ll one_time;
    ll over_time;
    time(ll a = 0, ll b = 0) {
        one_time = a;
        over_time = b;
    }
    bool operator < (const time &a) const
    {
        return over_time > a.over_time;
    }
};
int T;
int l, n, m;
ll tim[1000000+10];
int main()
{
    cin >> T;
    int s = 0;
    while(T--) {
        s++;
        priority_queue<time> q;
        scanf("%d%d%d", &l, &n, &m);
        for (int i = 0; i < n; i++) {
            ll t;
            scanf("%lld", &t);
            q.push(time(t, t));
        }
        for (int i = 0; i < l; i++) {
            time t1 = q.top();
            q.pop();
            tim[i] = t1.over_time;
            q.push(time(t1.one_time, t1.one_time+t1.over_time));
        }
        priority_queue<time>p;
        ll max1 = 0;
        for (int i = 0; i < m; i++) {
            ll t;
            scanf("%lld", &t);
            p.push(time(t, t));
        }
        for (int i = l-1; i >= 0; i--) {
            time t1 = p.top();
            p.pop();
            max1 = max(max1,t1.over_time+tim[i]);
            p.push(time(t1.one_time, t1.one_time+t1.over_time));
        }
        printf("Case #%d: %lld\n",s,  max1);
    }
    return 0;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值