hdu 6000 Wash

6 篇文章 0 订阅


Wash

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


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


1T100 .
1L106 .
1N,M105 .
1Wi,Di109 .
 

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
 

Recommend
jiangzijing2015   |   We have carefully selected several similar problems for you:   6014  6013  6012  6011  6010 
题意:L件衣服,N个洗衣机,M个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少。

思路:这是ccpcfinal的题目,明显是贪心但是很难想出来,首先洗衣服所需的最短时间应该很容易想出来了,用优先队列弹出下一次先洗完的时间就好了,问题在于烘干,正解应该是倒过来想,假设全部洗完洪完所需的最小时间是x,那么在x时刻,烘干机全部都已经工作完毕了,即烘干机全部空闲,那么我们把时间倒过来看,烘干过程等于洗衣服过程,用同样的方法算出最快烘干时间,然后要最快的时间故肯定是小的+大的,最后取最大值就是我们想要的x了,思路有点复杂,很难说清楚,还是上代码吧。

#include<cstdio>  
#include<algorithm>  
#include<cstring>  
#include<iostream>  
#include<cmath>  
#include<queue>  
#include<functional>  
typedef long long LL;
using namespace std;
#define maxn 1000005
#define ll l,mid,now<<1  
#define rr mid+1,r,now<<1|1  
#define lson l1,mid,l2,r2,now<<1  
#define rson mid+1,r1,l2,r2,now<<1|1  
#define inf 0x3f3f3f3f  
const int mod = 1e9 + 7;
LL time[maxn];
struct node{
	LL base, next;
};
bool operator<(node a, node b){
	return a.next > b.next;
}
int main(){
	int t;
	scanf("%d", &t);
	for (int tcase = 1; tcase <= t; tcase++){
		int l, n, m;
		scanf("%d%d%d", &l, &n, &m);
		priority_queue<node>q;
		while (n--){
			int w;
			scanf("%lld", &w);
			q.push(node{ w, w });
		}
		for (int i = 0; i < l; i++){
			node now = q.top();
			q.pop();
			time[i] = now.next;
			q.push(node{ now.base, now.next + now.base });
		}
		while (!q.empty())
			q.pop();
		for (int i = 0; i < m; i++){
			int d;
			scanf("%lld", &d);
			q.push(node{ d, d });
		}
		LL ans = 0;
		for (int i = l - 1; i >= 0; i--){
			node now = q.top();
			q.pop();
			ans = max(ans, now.next + time[i]);
			q.push(node{ now.base, now.next + now.base });
		}
		printf("Case #%d: %lld\n", tcase, ans);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值