【HDU 6000】Wash(贪心)
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:
- A non-negative amount of time after Panda arrives at the laundromat, Panda places the load in an unoccupied washing machine i.
- Wi minutes later, he removes the load from the washing machine, placing it in a temporary holding basket (which has unlimited space)
- A non-negative amount of time later, he places the load in an unoccupied dryer j
- 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(贪心)的更多相关文章
- HDU 6000 - Wash
/* HDU 6000 - Wash [ 贪心 ] 题意: L 件衣服,N 个洗衣机,M 个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少 分析: 先求出L件 ...
- HDU - 6000 Wash(优先队列+贪心)
题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间. 分析: 1.优先队列处理出每件衣服最早的洗完时间. 2.优先队列 ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- 【hdu 6000】Wash
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 因为每件衣服都是没有区别的. 只有洗衣机不同会影响洗衣时间. 那么我们把每台洗衣机洗衣的时间一开始都加入到队列中. 比如{2,3,6 ...
- hdu 2037简单贪心--活动安排问题
活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
随机推荐
- Homebrew 常用命令
Homebrew 常用命令 Homebrew 介绍 Homebrew也称brew,macOS下基于命令行的最强大软件包管理工具,使用Ruby语言开发.类似于CentOS的yum或者Ubuntu的apt ...
- sql基础语法-创建表和约束
创建数据库表 USE SQL2016 IF OBJECT_ID('dbo.Employees','U') IS NOT NULL DROP TABLE dbo.Employees; Create TA ...
- 146 LRU Cache 最近最少使用页面置换算法
设计和实现一个 LRU(最近最少使用)缓存 数据结构,使它应该支持以下操作: get 和 put .get(key) - 如果密钥存在于缓存中,则获取密钥的值(总是正数),否则返回 -1.put(k ...
- 学好Mac常用命令,助力iOS开发
原文出处: Jack_lin(@Jack_Lin_IOS ) 厚重·技术 序言 在iOS开发的过程中,更多地注重iOS开发的效率,熟练使用Mac终端操作的常用命令,可以让你更好的游刃于iOS繁重的开发 ...
- Learn More Study Less `my notes`
整体性学习概念: 广泛扎实的基础知识 抽象知识成生活中的模型,便于记忆 融会贯通,创造新的东西 整体性学习组成 获取:积极阅读:标记并结合其他的知识点 主要观点 怎么记住:联系和比喻其他的知识 拓展和 ...
- 【学习笔记】二:在HTML中使用JavaScript
1.<script>标签 1)考虑到最大限度的浏览器兼容性和约定俗成,type属性使用:text/javascript. 2)标签建议放置到</body>标签前,提高用户体验( ...
- 秒杀Sublime Text的微软开源代码编辑工具Visual Studio Code
1. 下载链接: https://code.visualstudio.com/ 2. 秒开一个ASP.NET网站源码 3.编辑CSS颜色支持 4.Git支持 5.常用快捷键 Ctrl+Shift+P ...
- 将Chrome调试器里的JavaScript变量保存成本地JSON文件
我写了一个系列的文章,主要用来搜集一些供程序员使用的小工具,小技巧,帮助大家提高工作效率. 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diag ...
- (四)docker创建私人仓库
(一) 简介 仓库(Repository)是集中存放镜像的地方.仓库可以 被认为是一个具体的项目或目录.例如对于仓库地址 docker.sina.com.cn/centos:centos63 来说,d ...
- iOS代理模式
iOS代理模式的简单理解:当一个对象无法直接获取到另一个对象的指针,又希望对那个变量进行一些操作时,可以使用代理模式. 代理主要由三部分组成: (1)协议:用来指定代理双方可以做什么,必须做什么. ( ...