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. C# 中使用Image.FromFile(string path)后,提示该文件正在被另一进程使用XXX的问题

    C# 中使用Image.FromFile(string path)后,提示该文件正在被另一进程使用XXX的问题 C# 中使用Image.FromFile(string path)后,提示该文件正在被另 ...

  2. 位运算 UEST 84 Binary Operations

    题目传送门 题意:所有连续的子序列的三种位运算计算后的值的和的期望分别是多少 分析:因为所有连续子序列的组数有n * (n + 1) / 2种,所以要将他们分类降低复杂度,以ai为结尾的分成一组,至于 ...

  3. Lucas+中国剩余定理 HDOJ 5446 Unknown Treasure

    题目传送门 题意:很裸,就是求C (n, m) % (p1 * p2 * p3 * .... * pk) 分析:首先n,m<= 1e18, 要用到Lucas定理求大组合数取模,当然p[]的乘积& ...

  4. 150 Evaluate Reverse Polish Notation 逆波兰表达式求值

    求在 逆波兰表示法 中算术表达式的值.有效的运算符号包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰计数表达.例如:  ["2", "1&quo ...

  5. LinQ的高级查询

    模糊查询: //数据库 + 自定义名称 =new 数据库 //例子: mydbDataContext con = new mydbDataContext(); //模糊查询表达式中用.Contains ...

  6. PHP的加密方式

    1. MD5加密 string md5 ( string $str [, bool $raw_output = false ] ) 参数 str  --  原始字符串. raw_output  --  ...

  7. Java-学完一个月总结(javaSe学习路线)

    JavaSe的一个月 第一周 0410 基本数据类型:数据类型的转换:运算符:导入删除项目0411 分支结构if else:switch case ;while0412 do while ;for / ...

  8. CATransaction 知识

    CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务. 区分隐式动画和隐式事务:隐式动画通过隐式事务实现动画 . 区分显式动画和显式事务:显式动画有多种 ...

  9. python3 进程与线程

    1.进程定义 狭义的定义: 进程是正在运行的程序的实例. 广义的定义:进程是一个具有 一定独立功能的程序关于某个数据集合的一次运行活动.它可以申请和拥有系统资源,是一个动态的概念,是一个活动的实体.它 ...

  10. vs code 插件list

    vs code 插件list