2016 CCPC-Final B

来源:互联网 发布:系统服务 软件更新 编辑:程序博客网 时间:2024/05/17 02:18

B - Wash
Time limit 10000 ms
Memory limit 32768 kB

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 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.
∙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

题目大意:有l件衣服要洗,有n个洗衣机,m个烘干机,衣服必须先洗了再烘干。
单就考虑洗衣服的话很简单,排个序先取小的就好了,但是还有个烘干,感觉上应该是衣服洗得快的+烘干慢的,这样所有的时间才会最小,不然MAX(洗衣)+(烘干)肯定是最大的呀! (´・ω・`)
所以在这里用到了优先队列 priority_queue,这个在很多时候都是蛮好用的,嘻嘻。
用两个优先队列分别由小到大排,然后大+小,最后输出就好啦。

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;int zu;int l,n,m;long long int time[1000005];//注意题目给你的大小!!!一开始我1e5+5写习惯了,wa了好几遍 (>_<、)typedef pair<long long ,long long > p;//注意要long long,不然会TLE,我也不知为啥会是TLE而不是WA (; 。。) int main(){    int k=1;    scanf("%d",&zu);    while(zu--)    {        priority_queue<p,vector<p>,greater<p> >w,d;        long long int t;        scanf("%d%d%d",&l,&n,&m);        for(int i=0;i<n;i++)        {            scanf("%lld",&t);            w.push(p(t,t));        }        for(int i=0;i<m;i++)        {            scanf("%lld",&t);            d.push(p(t,t));        }        for(int i=0;i<l;i++)        {            p temp=w.top();            w.pop();            time[i]=temp.first;            temp.first+=temp.second;//用过一次,时间累加,要是累加后时间还是很小下一次还是可以选择用它!            w.push(temp);        }        long long int sum=0;//注意初始化为0        for(int i=l-1;i>=0;i--)        {            p temp=d.top();            d.pop();            sum=max(sum,temp.first+time[i]);            temp.first+=temp.second;            d.push(temp);        }        printf("Case #%d: %lld\n",k++,sum);    }}
原创粉丝点击