【HDU 6000 Wash】优先队列 & 贪心
2017-10-07 17:42
369 查看
Wash
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 64000/64000 K (Java/Others)
Total Submission(s): 1076 Accepted Submission(s): 283
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!
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
∙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
2016 CCPC-Final
Recommend
jiangzijing2015 | We have carefully selected several similar problems for you: 6216 6215 6214 6213 6212
题意 : N 台洗衣机,M 台烘干机,把 L 件衣服洗完烘干最少需要多少时间
思路 : 洗完每件衣服的最短时间可以用优先队列保存,并记录下来,然后再用优先队列处理烘干机,贪心,对于最后一个洗完的衣服让烘干最快的烘干机去烘干
AC代码:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 64000/64000 K (Java/Others)
Total Submission(s): 1076 Accepted Submission(s): 283
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!
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
∙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
2016 CCPC-Final
Recommend
jiangzijing2015 | We have carefully selected several similar problems for you: 6216 6215 6214 6213 6212
题意 : N 台洗衣机,M 台烘干机,把 L 件衣服洗完烘干最少需要多少时间
思路 : 洗完每件衣服的最短时间可以用优先队列保存,并记录下来,然后再用优先队列处理烘干机,贪心,对于最后一个洗完的衣服让烘干最快的烘干机去烘干
AC代码:
#include<cstdio> #include<cmath> #include<deque> #include<queue> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int MAX = 1e6 + 10; const int INF = 1e9 + 7; typedef long long LL; #define p pair<LL,LL> priority_queue <p,vector<p>,greater<p> > q; LL t[MAX]; int main() { int T,nl = 0; scanf("%d",&T); while(T--){ while(!q.empty()) q.pop(); int L,N,M; LL x; p w; scanf("%d %d %d",&L,&N,&M); for(int i = 1; i <= N; i++){ scanf("%lld",&x); q.push(p(x,x)); } for(int i = 1; i <= L; i++){ w = q.top(); q.pop(); t[i] = w.first; q.push(p(w.first + w.second,w.second)); } while(!q.empty()) q.pop(); for(int i = 1; i <= M; i++){ scanf("%lld",&x); q.push(p(x,x)); } LL ans = 0; for(int i = L; i >= 1; i--){ w = q.top(); q.pop(); ans = max(ans,t[i] + w.first); q.push(p(w.first + w.second,w.second)); } printf("Case #%d: %lld\n",++nl,ans); } return 0; }
相关文章推荐
- [贪心&&优先队列]uva10954 Add All
- HDU 6000 Wash (优先队列-贪心)
- 22th【贪心&&优先队列】打地鼠游戏
- Codeforces 913DToo Easy Problems (优先队列 & 贪心)
- HDU 6000 Wash【优先队列优化贪心】【最大值+最小值】
- 51Nod 1163 最高的奖励(贪心+优先队列 & 并差集)
- Vijos-P1097-合并果子(简单贪心 && 优先队列 && c++)
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
- 数据结构Java实现07----队列:顺序队列&顺序循环队列、链式队列、顺序优先队列
- Maximum Sequence 贪心 优先队列
- AGC018:Coins(优先队列 & 思维)
- 【高效程序设计——贪心】UVa 10954 优先队列
- LA - 4254,二分,优先队列,贪心
- POJ 3614 Sunscreen 优先队列 贪心
- 【BZOJ】1692 & 1640: [Usaco2007 Dec]队列变换(后缀数组+贪心)
- POJ2431 Expedition【贪心+优先队列】
- POJ - 2431 Expedition :贪心+优先队列
- hdu 1242 Rescue(优先队列 && 广搜BFS)
- 51NOD 1163——最高的奖励(可用优先队列解决的贪心问题)