hdu6000 Wash ccpc-20162017-finals B Wash
Posted weeping
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu6000 Wash ccpc-20162017-finals B Wash相关的知识,希望对你有一定的参考价值。
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6000
题目:
Wash
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 64000/64000 K (Java/Others)
Total Submission(s): 1250 Accepted Submission(s): 331
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!
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.
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.
?1≤T≤100.
?1≤L≤106.
?1≤N,M≤105.
?1≤Wi,Di≤109.
limits
?1≤T≤100.
?1≤L≤106.
?1≤N,M≤105.
?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
Source
思路:
第一阶段,正着贪心,用set或优先队列维护,处理出每件衣服出来的时间。
第二阶段,倒着贪心,用set或优先队列维护,然后维护最大值。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define MP make_pair 6 #define PB push_back 7 typedef long long LL; 8 typedef pair<int,int> PII; 9 const double eps=1e-8; 10 const double pi=acos(-1.0); 11 const int K=1e6+7; 12 const int mod=1e9+7; 13 14 namespace fastIO{ 15 #define BUF_SIZE 100000 16 bool IOerror=0; 17 inline char nc(){ 18 static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; 19 if(p1==pend){ 20 p1=buf; 21 pend=buf+fread(buf,1,BUF_SIZE,stdin); 22 if(pend==p1){ 23 IOerror=1; 24 return -1;; 25 } 26 }return *p1++; 27 } 28 inline bool blank(char ch){ 29 return ch==‘ ‘||ch==‘\n‘||ch==‘\r‘||ch==‘\t‘; 30 } 31 inline bool read(int &x){ 32 char ch; 33 while(blank(ch=nc())); 34 if(IOerror)return 0; 35 for(x=ch-‘0‘;(ch=nc())>=‘0‘&&ch<=‘9‘;x=x*10+ch-‘0‘); 36 return 1; 37 } 38 #undef BUF_SIZE 39 }; 40 using namespace fastIO; 41 42 struct node 43 { 44 LL id,end; 45 node(){} 46 node(LL x,LL y){id=x,end=y;} 47 bool operator < (const node &ta) const 48 { 49 return end>ta.end||(end==ta.end&&id<ta.id); 50 } 51 }; 52 int n,m,l,ta[K],tb[K]; 53 LL ed[K]; 54 priority_queue<node>pa,pb; 55 56 int main(void) 57 { 58 //freopen("in.acm","r",stdin); 59 int t,cs=1;read(t); 60 while(t--) 61 { 62 LL ans=0; 63 while(pa.size())pa.pop(); 64 while(pb.size())pb.pop(); 65 read(l),read(n),read(m); 66 for(int i=1;i<=n;i++) 67 read(ta[i]),pa.push(node(i*1LL,1LL*ta[i])); 68 for(int i=1;i<=l;i++) 69 { 70 LL tm=pa.top().end,id=pa.top().id; 71 ed[i]=tm; 72 pa.pop(),pa.push(node(id,tm+ta[id])); 73 } 74 for(int i=1;i<=m;i++) 75 read(tb[i]),pb.push(node(i*1LL,1LL*tb[i])); 76 for(int i=l;i;i--) 77 { 78 LL tm=pb.top().end,id=pb.top().id; 79 ans=max(ans,ed[i]+tm); 80 pb.pop(),pb.push(node(id,tm+tb[id])); 81 } 82 printf("Case #%d: %lld\n",cs++,ans); 83 } 84 return 0; 85 }
以上是关于hdu6000 Wash ccpc-20162017-finals B Wash的主要内容,如果未能解决你的问题,请参考以下文章