Wash

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
题意:给出L堆衣服,在给n个洗衣机洗一堆衣服要的时间n[i]和m个烘干机烘干一堆衣服要的时间m[i],
衣服洗了可以先放着不烘干,想要得到最快洗完并烘干所有衣服所要的时间。
解题思路:先贪心最快洗完衣服的时间,要使得总时间最小,则最晚洗完的衣服应该用最快的烘干机烘干,所以先把洗衣时间排进优先队列,
洗过衣服的洗衣机再洗一遍可能比没洗过的洗衣机还要快(一个洗衣机多次使用的情况),取出队列队首之后再把队首加上已使用的时间再加入队列,
洗烘干衣服同理,烘干所需的最长时间取决于最后烘干完的衣服,取衣服烘干的过程中取Max
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 0x3f3f3f3f
const ll MAXN = 1e6 + ;
const ll MOD = 1e9 + ;
const double pi = acos(-);
ll w, d;
ll cah1[MAXN], cah2[MAXN];
typedef pair<ll, ll> p;
int main()
{
int t, cnt = ;
scanf("%d", &t);
while (t--)
{
priority_queue<p, vector<p>, greater<p> > q1;
priority_queue<p, vector<p>, greater<p> > q2;
ll l, n, m;
p t;
scanf("%lld%lld%lld", &l, &n, &m);
for (int i = ; i < n; i++)
{
scanf("%lld", &w);
q1.push(p(w, w));
//洗衣服的时间 和第几台
}
for (int i = ; i < m; i++)
{
scanf("%lld", &d);
q2.push(p(d, d));
}
for (int i = ; i < l; i++)
{
t = q1.top();
q1.pop();
cah1[i] = t.first; //cah存时间
q1.push(p(t.first + t.second, t.second)); //若是时间小继续使用
}
ll ans = ;
for (int i = l - ; i >= ; i--)
{
t = q2.top();
q2.pop();
ans = max(t.first + cah1[i], ans);
q2.push(p(t.first+t.second,t.second));
}
printf("Case #%d: %lld\n", cnt++, ans);
}
return ;
}
 

2016 CCPC-Final-Wash(优先队列+贪心)的更多相关文章

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

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

  2. 2016 CCPC 东北地区重现赛

    1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟,双端队列 1.题意:模拟一个栈的操 ...

  3. HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)

    题目链接  2016 CCPC东北地区大学生程序设计竞赛 B题 题意  给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...

  4. 最高的奖励 - 优先队列&贪心 / 并查集

    题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: ...

  5. POJ2431 优先队列+贪心 - biaobiao88

    以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...

  6. hdu3438 Buy and Resell(优先队列+贪心)

    Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution

    Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution 题目链接:https://atcoder.jp/contests/cf16- ...

  8. 【2018 CCPC网络赛】1001 - 优先队列&贪心

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...

  9. 2016 ccpc 网络选拔赛 F. Robots

    Robots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

随机推荐

  1. python OrderedDict

    15年16年接触python时候,还不知道这个函数,只知道dict的无序,造成了一些麻烦 今天view 代码,发现了 OrderedDict() 在python2.7中比较吃内存 pop(获取指定ke ...

  2. Web_telnet 通过JAVA实现网页上面的命令行远程工具 以及对于流的理解

    前言 这几天研究了一下如何在web页面上通过telnet 连接一个远程的机器,通过命令行进行控制,让然,B/S架构的项目,如果直接通过 浏览器是无法和远程机器进行通信的,我们就得借助后端来帮助实现这样 ...

  3. 关于js如果控制标签的字符长度

    js名字长度限定(如限制为50个字符,超过的显示...) var new_playerName = ""; jQuery(".translate").each( ...

  4. Hive性能优化(全面)

    1.介绍 首先,我们来看看Hadoop的计算框架特性,在此特性下会衍生哪些问题? 数据量大不是问题,数据倾斜是个问题. jobs数比较多的作业运行效率相对比较低,比如即使有几百行的表,如果多次关联多次 ...

  5. 在win64上使用bypy进行百度网盘文件上传

    阿里云服务器的带宽为2M,网站每日的备份包都3G多了,离线下载太费时间了,打算每日将备份包自动上传到自己的百度云盘里.1.先安装Python 执行python -V ,发现没安装python2.去py ...

  6. $POJ$3252 $Round\ Numbers$ 数位$dp$

    正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...

  7. java做插入时ID为自增获取到ID

    <selectKey keyProperty="id" resultType="int" order="AFTER"> sele ...

  8. 两个int数组对比,返回差异数据

    public static int[] DataDifference(int[] more, int[] few) { //差异Id var sbuNoItapSessionId = new int[ ...

  9. CS系列(一):Cobalt Strike初体验

    0X01 环境准备 Cobalt Strike安装包(链接:https://pan.baidu.com/s/1wCHJcJrF6H0wUCdetz3Xjg 提取码:rjuj) Cobalt Strik ...

  10. 【原创】Android adb错误“'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件。”处理方法

    才刚刚接触Android没多久,现在使用adb命令的时候出现错误“'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件.”,如下图所示: 这个问题一般有两种可能: 1.就是没有配置环境变量, ...