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

题解


先考虑洗衣服的过程,对于每一件衣服,我们取当前已耗时间最小的洗衣机,这样可以的到每一件衣服的最早被清洗完成的时间a[i]。再考虑烘干衣服的过程,对于每一件已经被清洗的衣服,我们取当前已耗时间最小的烘干机,这样可以得到每件衣服加工完成的时间,取最大的即可。

参考代码

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define inf 1000000000
#define PI acos(-1)
#define REP(i,x,n) for(int i=x;i<=n;i++)
#define DEP(i,n,x) for(int i=n;i>=x;i--)
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void Out(ll a){
if(a<0) putchar('-'),a=-a;
if(a>=10) Out(a/10);
putchar(a%10+'0');
}
const int N=1e6+10;
struct node{
ll x,y;
bool operator < (const node &an) const{
return y>an.y;
}
};
ll a[N];
int main(){
int T=read();
REP(i,1,T){
int l=read(),n=read(),m=read();
int d;
priority_queue<node>que;
REP(i,1,n){
d=read();
que.push(node{d,d});
}
node tmp;
REP(i,1,l){
tmp=que.top();
que.pop();
a[i]=tmp.y;
que.push(node{tmp.x,tmp.x+tmp.y});
}
while(!que.empty()) que.pop();
REP(i,1,m){
d=read();
que.push(node{d,d});
}
ll ans=0;
DEP(i,l,1){
tmp=que.top();
que.pop();
ans=max(ans,tmp.y+a[i]);
que.push(node{tmp.x,tmp.y+tmp.x});
}
printf("Case #%d: %lld\n",i,ans);
}
return 0;
}

【HDU 6000】Wash(贪心)的更多相关文章

  1. HDU 6000 - Wash

    /* HDU 6000 - Wash [ 贪心 ] 题意: L 件衣服,N 个洗衣机,M 个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少 分析: 先求出L件 ...

  2. HDU - 6000 Wash(优先队列+贪心)

    题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间. 分析: 1.优先队列处理出每件衣服最早的洗完时间. 2.优先队列 ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  5. 【hdu 6000】Wash

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 因为每件衣服都是没有区别的. 只有洗衣机不同会影响洗衣时间. 那么我们把每台洗衣机洗衣的时间一开始都加入到队列中. 比如{2,3,6 ...

  6. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. AtCoder Regular Contest 083 E - Bichrome Tree

    题目传送门:https://arc083.contest.atcoder.jp/tasks/arc083_c 题目大意: 给定一棵树,你可以给这些点任意黑白染色,并且赋上权值,现给定一个序列\(X_i ...

  2. Codeforces 1108F(克鲁斯卡尔的理解)

    最小生成树会多样的情况是:两个或多个边等长且连通同样的两个并查集块. 所以可以跑一遍克鲁斯卡尔,每次把当前等长的边数出来,注意不要边找边并查,因为有一部分边是正常跑生成树我们也不会要他的,这种直接跳了 ...

  3. 优先队列 POJ 3253 Fence Repair

    题目传送门 题意:一块木板按照某个顺序切成a[1], a[2]...a[n]的长度,每次切都会加上该两段木板的长度,问选择什么顺序切能使得累加和最小 分析:网上说这是哈夫曼树.很容易想到先切掉最长的, ...

  4. JAVA平台的理解

    主题:  JAVA是解释执行还是编译执行? 我的答案 : 混合模式 闲谈 : 1. JAVA(write once,run anywhere): 2. GC(Garbagae Collection), ...

  5. 关于对象.style currentstyle 的区别

    对象.style的方式只能获取行内写法的样式,但是外部引入的或者写在head里面的就无法获取,只能用currentstyle.

  6. 使用cordova把h5应用打包成apk

    由于h5应用开发不是本例重点,因此直接提供一个最简单的h5应用代码,此应用使用vue-cli框架开发 此h5应用叫vue1,用webstrom打开vue1,进行npm install安装引用 vue1 ...

  7. Google的Java编程风格指南

    作者:Hawstein出处:http://hawstein.com/posts/google-java-style.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Cre ...

  8. Oracle Storage in Action : 删除物理数据文件

    ALTER TABLESPACE XH_DM DROP DATAFILE 'F:\DEV\ORACLE-DATA\ORCL\XH_DM_1.DBF'; SQL> ALTER TABLESPACE ...

  9. 安装 配置 IIS

    一  .找到    控制面板 ------  在程序和功能  -----打开或关闭window 功能 :这里可能要等一下 才会显示 . 二‘.找到  Internet信息服务 ,勾选大部分如下图:点击 ...

  10. python基础一 day9 函数升阶(2)

    def max(a,b): return a if a>b else bprint(max(1, 2)) # 函数进阶# a = 1# def func():# print(a)# func() ...