HDU6000

来源:互联网 发布:广电网络三合一机顶盒 编辑:程序博客网 时间:2024/06/05 16:16

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 intstruct 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 0
原创粉丝点击