HDU 3433 A Task Process

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1368    Accepted Submission(s):
684

Problem Description
There are two kinds of tasks, namely A and B. There are
N workers and the i-th worker would like to finish one task A in ai minutes, one
task B in bi minutes. Now you have X task A and Y task B, you want to assign
each worker some tasks and finish all the tasks as soon as possible. You should
note that the workers are working simultaneously.
 
Input
In the first line there is an integer T(T<=50),
indicates the number of test cases.

In each case, the first line contains
three integers N(1<=N<=50), X,Y(1<=X,Y<=200). Then there are N
lines, each line contain two integers ai, bi (1<=ai, bi <=1000).

 
Output
For each test case, output “Case d: “ at first line
where d is the case number counted from one, then output the shortest time to
finish all the tasks.
 
Sample Input
3
2 2 2
1 10
10 1
2 2 2
1 1
10 10
3 3 3
2 7
5 5
7 2
Sample Output
Case 1: 2
Case 2: 4
Case 3: 6
 /*
二分+DP。
二分时间t,dp[i][j]表示在时间t内前i个人完成j件A任务所能完成的B任务的最大数量。如果dp[i][x]>=y
就是可以的。然后不断迭代得到ans。
*/
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>
#define N 70
int T,n,x,y,a[N],b[N];
void input(int &r)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
scanf("%d%d%d",&n,&x,&y);
for(int i=;i<=n;++i)
{
scanf("%d%d",&a[i],&b[i]);
r=max(r,max(a[i],b[i]));
}
}
bool check(int tim)
{
int f[]={};
memset(f,-,sizeof(f));
f[]=;
for(int i=;i<=x;++i)
if(tim>=a[]*i)
f[i]=(tim-a[]*i)/b[];
if(f[x]>=y) return true;
for(int i=;i<=n;++i)
{
for(int k=x;k>=;--k)
for(int j=k;j>=;--j)/*for(int j=0;j<=k;--j),结果更新f[i][k]的时候用的是他本身,如果改为for(int j=0;j<k;--j),又不能用f[i-1][k]来更新f[i][k],所以就改为了倒序*/
if(tim>=(k-j)*a[i]&&f[j]!=-)
f[k]=max(f[k],f[j]+(tim-a[i]*(k-j))/b[i]);
if(f[x]>=y) return true;
}
return false;
}
int find_ans(int l,int r)
{
int mid;
while(l<=r)
{
mid=(l+r)>>;
if(check(mid))
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
scanf("%d",&T);
int topt=;
while(T--)
{
++topt;
int l=,r=;
input(r);
r=r**max(x,y);
printf("Case %d: %d\n",topt,find_ans(l,r));
}
return ;
}
 

二分+DP HDU 3433 A Task Process的更多相关文章

  1. hdu 3433 A Task Process 二分+dp

    A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. hdu 3433 A Task Process(dp+二分)

    题目链接 题意:n个人, 要完成a个x任务, b个y任务. 求,最短的时间 思路:由于时间较大,用 二分来找时间. dp[i][j]表示 i个人完成j个x任务, 最多能完成的y任务个数 这个题 不是很 ...

  3. Hadoop:Task process exit with nonzero status of 1 异常

    在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. ...

  4. Linux中的task,process, thread 简介

    本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...

  5. Activity, Service,Task, Process and Thread之间的关系

    Activity, Service,Task, Process and Thread之间到底是什么关系呢? 首先我们来看下Task的定义,Google是这样定义Task的:a task is what ...

  6. hadoop系列 第三坑: Task process exit with nonzero status of 137

    跑MR的时候抛出异常: java.lang.Throwable: Child Error at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.j ...

  7. 2018.10.24 NOIP模拟 小 C 的数组(二分+dp)

    传送门 考试自己yyyyyy的乱搞的没过大样例二分+dp二分+dp二分+dp过了606060把我自己都吓到了! 这么说来乱搞跟被卡常的正解比只少101010分? 那我考场不打其他暴力想正解血亏啊. 正 ...

  8. 「学习笔记」wqs二分/dp凸优化

    [学习笔记]wqs二分/DP凸优化 从一个经典问题谈起: 有一个长度为 \(n\) 的序列 \(a\),要求找出恰好 \(k\) 个不相交的连续子序列,使得这 \(k\) 个序列的和最大 \(1 \l ...

  9. 【bzoj1044】[HAOI2008]木棍分割 二分+dp

    题目描述 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长度最小, 并且 ...

随机推荐

  1. python pip 升级每个包

    pip本身不自带升级所有包的功能, 但可以通过下面的脚本实现. import pip from subprocess import call for dist in pip.get_installed ...

  2. ValueStack值栈和ActionContext

    Struts2在OGNL之上提供的最大附加特性就是支持值栈(ValueStack),在OGNL上下文中只能有一个根对象,Struts2的值栈则允许存在许多虚拟对象. 一:值栈(ValueStack) ...

  3. [ASP.NET MVC] ASP.NET Identity学习笔记 - 原始码下载、ID型别差异

    [ASP.NET MVC] ASP.NET Identity学习笔记 - 原始码下载.ID型别差异 原始码下载 ASP.NET Identity是微软所贡献的开源项目,用来提供ASP.NET的验证.授 ...

  4. [Tool] 透过PowerPoint Online在部落格文章里内嵌简报

    [Tool] 透过PowerPoint Online在部落格文章里内嵌简报 前言 讲课的时候,用PowerPoint做简报,好像已经成了讲课的惯例.而在课后,将课堂简报整理成部落格的文章,如果单纯是在 ...

  5. 项目、SVN clean的一些事

    1.如果你发现你的文件修改了.Tomcat也重新了,但访问的还是旧的文件,这个时候你需要clean下你的项目. Clean will discard all build problems and bu ...

  6. RHEL7软件包管理

    本文介绍RHEL7的软件包管理 RHEL7下主要有RPM和YUM这两种包管理: YUM使用简单但需要联网,YUM会去网上的YUM包源去获取所需要的软件包并获取该包依赖的其他包 RPM的需要的操作精度比 ...

  7. Microsoft Dynamics CRM 前瑞开发

    做CRM开发最大的感受就是其前瑞开发过程中,调试起来比较麻烦,需要做一些断点还要配制一些浏览器设置,对新手来说比较困难.还有就是对REST调试,经常为了调试一个正确的结果而花费大量的时间.现在推荐一个 ...

  8. SharePoint固定的Footer

    原文地址:http://www.eliostruyf.com/sticky-footer-solution-for-sharepoint-2013/ 照搬全文: OFFICE 365 & SH ...

  9. 网络开始---多线程---NSThread-02-线程状态(了解)(三)

    #import "HMViewController.h" @interface HMViewController () @property (nonatomic, strong) ...

  10. Mac下Apache Tomcat安装配置

    Java Web如果稍微知道一点,一般对Tomcat都不会陌生,Apache是普通服务器,本身只支持html即普通网页,可以通过插件支持PHP,还可以与Tomcat连通(单向Apache连接Tomca ...