【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的几个矩形? /* ...
随机推荐
- 使用Git分布式版本控制系统
GIT(分布式版本控制系统) Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本 ...
- Java三大特性之---封装
封装从字面上来理解就是包装的意思,专业点就是信息隐藏,是指利用抽象数据类型将数据和基于数据的操作封装在一起,使其构成一个不可分割的独立实体,数据被保护在抽象数据类型的内部,尽可能地隐藏内部的细节,只保 ...
- LSP
Liskov Substitution Principle里氏替换原则,OCP作为OO的高层原则,主张使用“抽象(Abstraction)”和“多态(Polymorphism)”将设计中的静态结构改为 ...
- P1936 水晶灯火灵
题目描述 ,刚好符合以下③条规则:①m.n∈{1,2,……,k}②(n²-m*n-m²)²=1③m.n为整数. 输入输出格式 输入格式: Only one:k.(What?还是失败?) 输出格式: 共 ...
- MyBatis -- 必知必会
MyBatis的前身是Apache的一个开源项目iBatis,2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis.201 ...
- LeetCode 69 题
1.题目要求 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出 ...
- LN : leetcode 416 Partition Equal Subset Sum
lc 416 Partition Equal Subset Sum 416 Partition Equal Subset Sum Given a non-empty array containing ...
- Day01 计算机硬件基础
1.什么是编程语言? 编程语言是程序员与计算机沟通的介质. 2.什么是编程? 程序员利用某种编程语言的语法格式将自己脑子中想要让计算机做的事写到文件中. 所以说,变成的结果就是文件,文件的内容就是一堆 ...
- Centos5安装***
最近shadowsocks挺火,看了几张帖子,感觉在手机上应该挺好用,电脑都是挂着ssh,用不到***了,下面贴出服务器安装过程: yum install build-essential autoco ...
- UVA 11346 Probability 概率 (连续概率)
题意:给出a和b,表示在直角坐标系上的x=[-a,a] 和 y=[-b,b]的这样一块矩形区域.给出一个数s,问在矩形内随机选择一个点p=(x,y),则(0.0)和p点组成的矩形面积大于s的概率是多少 ...