zoukankan      html  css  js  c++  java
  • [HNOI 2001]产品加工

    Description

    某加工厂有A、B两台机器,来加工的产品可以由其中任何一台机器完成,或者两台机器共同完成。由于受到机器性能和产品特性的限制,不同的机器加工同一产品所需的时间会不同,若同时由两台机器共同进行加工,所完成任务又会不同。某一天,加工厂接到n个产品加工的任务,每个任务的工作量不尽一样。你的任务就是:已知每个任务在A机器上加工所需的时间t1, B机器上加工所需的时间t2及由两台机器共同加工所需的时间t3,请你合理安排任务的调度顺序,使完成所有n个任务的总时间最少。

    Input

    输入共n+1行第1行为 n。 n是任务总数(1≤n≤6000)第i+1行为3个[0,5]之间的非负整数t1,t2,t3,分别表示第i个任务在A机器上加工、B机器上加工、两台机器共同加工所需要的时间。如果所给的时间t1或t2为0表示任务不能在该台机器上加工,如果t3为0表示任务不能同时由两台机器加工。

    Output

    最少完成时间

    Sample Input

    5
    2 1 0
    0 5 0
    2 4 1
    0 0 3
    2 1 1

    Sample Output

    9

    题解

    我们令$f[i]$表示$A$机器耗时为$i$,$B$机器最少的耗时。

    显然我们可以边输入边处理。

    输入时我们先将每个非$INF$值加上$t_2$,

    对于枚举的

    $$f[i]=Min(f[i],f[i-t_1],f[i-t_3]+t_3)$$

    这样最后统计答案时

    $$ans=Min(ans,Max(i,f[i]))$$

     1 #include<set>
     2 #include<map>
     3 #include<cmath>
     4 #include<ctime>
     5 #include<queue>
     6 #include<stack>
     7 #include<cstdio>
     8 #include<string>
     9 #include<vector>
    10 #include<cstdlib>
    11 #include<cstring>
    12 #include<iostream>
    13 #include<algorithm>
    14 using namespace std;
    15 const int N=6000;
    16 const int INF=1e9;
    17 
    18 int Min(const int &a,const int &b) {return a<b ? a:b;}
    19 int Max(const int &a,const int &b) {return a>b ? a:b;}
    20 int n,m,ans;
    21 int t1,t2,t3;
    22 int f[N*5+5];
    23 
    24 int main()
    25 {
    26     scanf("%d",&n);
    27     memset(f,127,sizeof(f));
    28     f[0]=0;
    29     while (n--)
    30     {
    31         scanf("%d%d%d",&t1,&t2,&t3);
    32         t1=!t1 ? INF :t1;
    33         t2=!t2 ? INF :t2;
    34         t3=!t3 ? INF :t3;
    35         m+=Min(t1,Min(t2,t3));
    36         for (int i=m;i>=0;i--)
    37         {
    38             if (f[i]<INF) f[i]+=t2;
    39             if (i>=t1) f[i]=Min(f[i],f[i-t1]);
    40             if (i>=t3) f[i]=Min(f[i],f[i-t3]+t3);
    41         }
    42     }
    43     ans=INF;
    44     for (int i=0;i<=m;i++) ans=Min(ans,Max(i,f[i]));
    45     printf("%d
    ",ans);
    46     return 0;
    47 }
  • 相关阅读:
    python 基础到字符串学习
    Newtonsoft.Json 获取匿名类数据
    Abp Wcf结合使用问题
    Ef Migration 操作出现SQLEXPRESS
    No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误
    Ef Code First 发生”provider: SQL Network Interfaces, error: 26
    ef 多条数据插入处理方案(据说还有更好的)
    记录一次 HttpWebRequest 尝试自动重定向太多 错误
    NetCore 下使用RSA加密,解密;并且前端使用jsencrypt.js实现Rsa相关方法。
    The specified framework version '2.0' could not be parsed 错误处理
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/7413641.html
Copyright © 2011-2022 走看看