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. C语言中的断言

    一.原型定义:void assert( int expression ); assert宏的原型定义在<assert.h>中,其作用是先计算表达式 expression ,如果expres ...

  2. 9. SOFAJRaft源码分析— Follower如何通过Snapshot快速追上Leader日志?

    前言 引入快照机制主要是为了解决两个问题: JRaft新节点加入后,如何快速追上最新的数据 Raft 节点出现故障重新启动后如何高效恢复到最新的数据 Snapshot 源码分析 生成 Raft 节点的 ...

  3. SQLServer数据库之SqlServer查看表、存储过程、耗时查询、当前进程、开销较大的语句

    --查看数据库中表的语句 SELECT s2.dbid , DB_NAME(s2.dbid) AS [数据库名] , --s1.sql_handle , ( , ( ( THEN ( LEN(CONV ...

  4. eclipse中竖行选择代码的快捷键

    Alt+Shift+A   (竖行选择代码)

  5. C# ref参数

    ref关键字用于将方法内的变量改变后带出方法外.具体我们通过例子来说明: static void Main(string[] args) { int c = 0; Add(1, 2,ref c); C ...

  6. Tomcat从安装到配置Https SSL证书

    为什么要写本文? 今天一个群友在群里问怎么给Tomcat配置SSL,也就是HTTPS,他买的阿里云的服务器,自带公网ip,还找到了免费的SSL证书 既然@我了,我就帮忙搞一搞呗,我就要了一个带sudo ...

  7. 敏捷开发:代码Review

    热情高涨 代码走查作为一种流程形式,起初大家的参与热情非常高涨. 因为,自己可以学习到别人一些巧妙的思想,自己的代码和习惯都暴漏出来. 这个过程中不断地吸收和改正. 但是...... 我们一开始组织的 ...

  8. fiddler 手机 https 抓包

    fiddler手机抓包原理fiddler手机抓包的原理与抓pc上的web数据一样,都是把fiddler当作代理,网络请求走fiddler,fiddler从中拦截数据,由于fiddler充当中间人的角色 ...

  9. CCPC-Wannafly Winter Camp Day1 (Div2 ABCFJ) 待补...

    Day1 Div2 场外链接 按题目顺序~ A 机器人 传送门 题意:有两条平行直线A.B,每条直线上有n个点,编号为1~n.在同一直线上,从a站点到b站点耗时为两点间的距离.存在m个特殊站点,只有在 ...

  10. BitSet 的使用

    BitSet 的简单介绍 BitSet,即位图,是位操作的对象,值只有 0 或 1(即 false 或 true). Java 的 BitSet 内部维护着一个 long 数组,默认初始化时数组的长度 ...