2017 CCPC Final B Wash

来源:互联网 发布:notebook软件 编辑:程序博客网 时间:2024/06/06 04:39

Wash

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


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.Theith 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
21 1 11200342 3 2100 10 110 10
 

Sample Output
Case #1: 1234Case #2: 12


题目描述:给定L(1 <= L <= 1e6)件衣服,有n(1<=n<=1e5)个洗衣机,每个洗衣服需要的时间是w[i],有m(1<=m<=1e5)个烘干机,每个烘干的时间是d[i],每件衣服都要先洗再烘干,两种机器同时都只能处理一件衣服,现在问处理完所有衣服需要多少时间?

题目思路:将洗衣服和烘干看成两个独立的过程来考虑。首先,我们处理出前L件衣服每件洗完的最小时间(这个时间是从第一个洗衣机开始工作计时的),将其中第i件洗完的最小时间记录在a[i];然后,我们处理出用烘干机烘干L件衣服时每件烘干完的最小时间(这个时间是从第一个烘干机开始工作计时的),将其中第i件烘干完的最小时间记录在b[i]。上述两个过程可以用优先队列实现,而且我们注意到,这两个过程是相互独立的,烘干L件的时间与洗L件的时间互相没有联系。最后,我们就是要知道第i件洗的衣服是第几件烘干的,假如第i件洗完的衣服是第j件烘干的,那么这件衣服完成整个流程的时间就是a[i] + b[j],所以说,就是要把a数组和b数组中元素两两配对,要求其中和最大的一对的和最小,这个和就是答案。

收获:具有相互影响的问题应该尝试寻找其中互不影响的问题,是否能从互不影响的问题中探寻答案。

#pragma warning(disable:4786)#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<map>#include<set>#include<vector>#include<cmath>#include<string>#include<sstream>#include<bitset>#define LL long long#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define mem(a,x) memset(a,x,sizeof(a))#define lson l,m,x<<1#define rson m+1,r,x<<1|1using namespace std;const int INF = 0x3f3f3f3f;const int mod = 1e9 + 7;const double PI = acos(-1.0);const double eps=1e-6;inline bool scan_d(int &num){        char in;bool IsN=false;        in=getchar();        if(in==EOF) return false;        while(in!='-'&&(in<'0'||in>'9')) in=getchar();        if(in=='-'){ IsN=true;num=0;}        else num=in-'0';        while(in=getchar(),in>='0'&&in<='9'){                num*=10,num+=in-'0';        }        if(IsN) num=-num;        return true;}struct node{    LL time , id;    bool operator < (const node & rhs) const    {        return time > rhs.time;    }};const int maxn = 1e5 + 5;int w[maxn] , d[maxn] ;LL clo[maxn * 10];int main(){    int T , L , n , m , kase = 0;    scanf("%d", &T);    while(T--){        scanf("%d %d %d", &L , &n , &m);        node st , cur;        priority_queue<node>Q1 , Q2;        for(int i =1 ; i <= n; i++){           scan_d(w[i]);            st.time = w[i];     st.id = i;            Q1.push(st);        }        for(int i = 1 ; i<= m; i++){            scan_d(d[i]);            st.time = d[i];     st.id = i;            Q2.push(st);        }        for(int i = 1 ; i <= L ; i++){            cur = Q1.top();      Q1.pop();            clo[i] = cur.time;            st.time = cur.time + w[cur.id];         st.id = cur.id;            Q1.push(st);        }       LL ans = -1;        for(int i = L ; i >= 1 ; --i){            cur = Q2.top();     Q2.pop();            ans = max(ans , clo[i] + cur.time);            st.time = cur.time + d[cur.id];         st.id = cur.id;            Q2.push(st);        }        printf("Case #%d: %lld\n",++kase , ans);    }    return 0;}


0 0