2016 CCPC-Final-Wash(优先队列+贪心)
Wash
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
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
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(优先队列+贪心)的更多相关文章
- HDU - 6000 Wash(优先队列+贪心)
题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间. 分析: 1.优先队列处理出每件衣服最早的洗完时间. 2.优先队列 ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)
题目链接 2016 CCPC东北地区大学生程序设计竞赛 B题 题意 给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...
- 最高的奖励 - 优先队列&贪心 / 并查集
题目地址:http://www.51cpc.com/web/problem.php?id=1587 Summarize: 优先队列&贪心: 1. 按价值最高排序,价值相同则按完成时间越晚为先: ...
- POJ2431 优先队列+贪心 - biaobiao88
以下代码可对结构体数组中的元素进行排序,也差不多算是一个小小的模板了吧 #include<iostream> #include<algorithm> using namespa ...
- hdu3438 Buy and Resell(优先队列+贪心)
Buy and Resell Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution
Atcoder CODE FESTIVAL 2016 Grand Final E - Water Distribution 题目链接:https://atcoder.jp/contests/cf16- ...
- 【2018 CCPC网络赛】1001 - 优先队列&贪心
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...
- 2016 ccpc 网络选拔赛 F. Robots
Robots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
随机推荐
- Visual Studio 2017 安装心得
既然VS2017已经发布了,就想安装一下试试,先卸载VS2015, 网上有个完全卸载的东东,https://github.com/Microsoft/VisualStudioUninstaller/r ...
- linux-head、tail、sort、uniq、pstree、ps
1.head 默认查看文件前10行 head -7 /etc/yum.conf -n num -n7代表查看文件前7行 2.tail 默认查看文件的后10行 tail -7 /etc/yum.conf ...
- Python 进程、线程、协程的介绍与使用
一.必备的理论基础 二.操作系统发展史 三.进程理论 四.线程理论 五.协程 一.必备的理论基础 操作系统理论: 操作系统是一个协调\管理\控制计算机硬件资源与应用软件资源的控制程序 操作系统的两大功 ...
- 基于 HTML5 WebGL 与 WebVR 3D 虚实现实的可视化培训系统
前言 2019 年 VR, AR, XR, 5G, 工业互联网等名词频繁出现在我们的视野中,信息的分享与虚实的结合已经成为大势所趋,5G 是新一代信息通信技术升级的重要方向,工业互联网是制造业转型升级 ...
- C#操作注册表(简单方便,兼容X32和X64)
C#操作注册表(简单方便,兼容X32和X64) 大家好,我在这里给大家介绍本人实现的操作注册表的类,简单方便,兼容32位系统和64位系统. 一般大家用C#操作注册的方法是使用命名空间Microsoft ...
- 【记】VirtualBox安装CentOS6
推荐随笔 VirtualBox中安装CentOS-6.6虚拟机 问题1: 在选择虚拟硬盘大小时,最好不要用默认的8G 我的分区 /boot 200M swap 1024M /home 4096M / ...
- centos7 安装jdk8和maven3
centos7 安装jdk8和maven3 标签(空格分隔): java,linux jdk 第一种安装: yum install java-1.8.0-openjdk /usr/lib/jvm/ 默 ...
- ubuntu pycharm、idea创建快捷方式
编辑/usr/share/application/pycharm.desktop [Desktop Entry] Type=Application Name=Pycharm GenericName=P ...
- 微信小程序----日期时间选择器(自定义精确到分秒或时段)
声明 bug:由于此篇博客是在bindcolumnchange事件中做的值的改变处理,因此会出现当你选择时,没有点击确定,直接取消返回后,会发现选择框的值依然改变.造成原因:这一点就是由于在bindc ...
- python的list()函数
list()函数将其它序列转换为 列表 (就是js的数组). 该函数不会改变 其它序列 效果图一: 代码一: # 定义一个元组序列 tuple_one = (123,','abc') print( ...