zoukankan      html  css  js  c++  java
  • 二分+DP HDU 3433 A Task Process

    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
     1 /*
     2 二分+DP。 
     3 二分时间t,dp[i][j]表示在时间t内前i个人完成j件A任务所能完成的B任务的最大数量。如果dp[i][x]>=y 
     4 就是可以的。然后不断迭代得到ans。
     5 */
     6 #include<iostream>
     7 using namespace std;
     8 #include<cstdio>
     9 #include<cstring>
    10 #define N 70
    11 int T,n,x,y,a[N],b[N];
    12 void input(int &r)
    13 {
    14     memset(a,0,sizeof(a));
    15     memset(b,0,sizeof(b));
    16     scanf("%d%d%d",&n,&x,&y);
    17     for(int i=1;i<=n;++i)
    18     {
    19         scanf("%d%d",&a[i],&b[i]);
    20         r=max(r,max(a[i],b[i]));
    21     }
    22 }
    23 bool check(int tim)
    24 {
    25     int f[230]={0};
    26     memset(f,-1,sizeof(f));
    27     f[0]=0;
    28     for(int i=0;i<=x;++i)
    29       if(tim>=a[1]*i)
    30       f[i]=(tim-a[1]*i)/b[1];
    31     if(f[x]>=y) return true;
    32     for(int i=2;i<=n;++i)
    33     {
    34         for(int k=x;k>=0;--k)
    35           for(int j=k;j>=0;--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],所以就改为了倒序*/
    36           if(tim>=(k-j)*a[i]&&f[j]!=-1)
    37             f[k]=max(f[k],f[j]+(tim-a[i]*(k-j))/b[i]);
    38        if(f[x]>=y) return true;
    39     }
    40     return false;
    41 }
    42 int find_ans(int l,int r)
    43 {
    44     int mid;
    45     while(l<=r)
    46     {
    47         mid=(l+r)>>1;
    48         if(check(mid))
    49         {
    50             r=mid-1;
    51         }
    52         else l=mid+1;
    53     }
    54     return l;
    55 }
    56 int main()
    57 {
    58     scanf("%d",&T);
    59     int topt=0;
    60     while(T--)
    61     {
    62         ++topt;
    63         int l=1,r=0;
    64         input(r);
    65         r=r*2*max(x,y);
    66         printf("Case %d: %d
    ",topt,find_ans(l,r));
    67     }
    68     return 0;
    69  } 
     
  • 相关阅读:
    Django中获取参数(路径,查询,请求头,请求体)
    正则表达式基础、原理
    每日总结【2020/02/12】
    【家庭记账本】Android开发(初稿)
    每日总结【2020/02/11】
    【家庭记账本】Android开发日记(九)
    【家庭记账本】Android开发日记(八)
    【家庭记账本】Android开发(提交稿件)
    每日总结【2020/02/09】
    《构建之法》阅读笔记(三)
  • 原文地址:https://www.cnblogs.com/c1299401227/p/5592095.html
Copyright © 2011-2022 走看看