地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6000

题目:

Wash

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 64000/64000 K (Java/Others)
Total Submission(s): 1250    Accepted Submission(s): 331

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:
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
 
Source

思路:

  第一阶段,正着贪心,用set或优先队列维护,处理出每件衣服出来的时间。

  第二阶段,倒着贪心,用set或优先队列维护,然后维护最大值。

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; namespace fastIO{
#define BUF_SIZE 100000
bool IOerror=;
inline char nc(){
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend){
p1=buf;
pend=buf+fread(buf,,BUF_SIZE,stdin);
if(pend==p1){
IOerror=;
return -;;
}
}return *p1++;
}
inline bool blank(char ch){
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
inline bool read(int &x){
char ch;
while(blank(ch=nc()));
if(IOerror)return ;
for(x=ch-'';(ch=nc())>=''&&ch<='';x=x*+ch-'');
return ;
}
#undef BUF_SIZE
};
using namespace fastIO; struct node
{
LL id,end;
node(){}
node(LL x,LL y){id=x,end=y;}
bool operator < (const node &ta) const
{
return end>ta.end||(end==ta.end&&id<ta.id);
}
};
int n,m,l,ta[K],tb[K];
LL ed[K];
priority_queue<node>pa,pb; int main(void)
{
//freopen("in.acm","r",stdin);
int t,cs=;read(t);
while(t--)
{
LL ans=;
while(pa.size())pa.pop();
while(pb.size())pb.pop();
read(l),read(n),read(m);
for(int i=;i<=n;i++)
read(ta[i]),pa.push(node(i*1LL,1LL*ta[i]));
for(int i=;i<=l;i++)
{
LL tm=pa.top().end,id=pa.top().id;
ed[i]=tm;
pa.pop(),pa.push(node(id,tm+ta[id]));
}
for(int i=;i<=m;i++)
read(tb[i]),pb.push(node(i*1LL,1LL*tb[i]));
for(int i=l;i;i--)
{
LL tm=pb.top().end,id=pb.top().id;
ans=max(ans,ed[i]+tm);
pb.pop(),pb.push(node(id,tm+tb[id]));
}
printf("Case #%d: %lld\n",cs++,ans);
}
return ;
}

最新文章

  1. Anciroid的IPC机制-Binder概述
  2. 烂泥:学习ubuntu远程桌面(二):远程桌面会话管理
  3. 经典非原创,网页常用Javascript
  4. homework01
  5. [转] NSString / NSMutableString 字符串处理,常用代码
  6. Ruby on Rails Tutorial读书笔记-1
  7. Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看。
  8. (译)Windsor入门教程---第一部分 获取Windsor
  9. OpenCV——PS图层混合算法(六)
  10. 使用FFmpeg捕获一帧摄像头图像
  11. MockPlus原型设计介绍
  12. [04-05]box框模型(Box Model)定义了元素框处理元素内容、内边距、边框和外边距的方式
  13. Civil 3D 二次开发 新建CLR项目出现错误C2143
  14. Nginx 安装配置文件解析
  15. 17.纯 CSS 创作炫酷的同心矩形旋转动画
  16. 20155337《网络对抗》Exp5 MSF基础应用
  17. 第一个struct2程序(2)
  18. SVN的标准目录结构:trunk、branches、tags
  19. maven项目搜索依赖jar包顺序
  20. vue-cli router的使用

热门文章

  1. Unity3D Mecanim :Body Mask的使用、 角色Retargeting原理分析、Apply RootMotion
  2. Unity3D笔记 愤怒的小鸟&lt;三&gt; 实现Play界面2
  3. wpgcms---banner图怎么调用
  4. C++/C, Java学习资料
  5. 2018-2019-2 20165330《网络对抗技术》Exp3 免杀原理与实践
  6. 线段树(Segment Tree)总结
  7. Luogu 3373 - 【模板】线段树 2 - [加乘线段树]
  8. 11.21 CSS学习-下午
  9. Linux:file命令显示自定义文件类型
  10. mysql数据库的相关练习题及答案