zoukankan      html  css  js  c++  java
  • USACO 4.2 Job Processing

    Job Processing
    IOI'96

    A factory is running a production line that requires two operations to be performed on each job: first operation "A" then operation "B". Only a certain number of machines are capable of performing each operation.

    Figure 1 shows the organization of the production line that works as follows. A type "A" machine takes a job from the input container, performs operation "A" and puts the job into the intermediate container. A type "B" machine takes a job from the intermediate container, performs operation "B" and puts the job into the output container. All machines can work in parallel and independently of each other, and the size of each container is unlimited. The machines have different performance characteristics, a given machine requires a given processing time for its operation.

    Give the earliest time operation "A" can be completed for all N jobs provided that the jobs are available at time 0. Compute the minimal amount of time that is necessary to perform both operations (successively, of course) on all N jobs.

    PROGRAM NAME: job

    INPUT FORMAT

    Line 1: Three space-separated integers:
    • N, the number of jobs (1<=N<=1000).
    • M1, the number of type "A" machines (1<=M1<=30)
    • M2, the number of type "B" machines (1<=M2<=30)
    Line 2..etc: M1 integers that are the job processing times of each type "A" machine (1..20) followed by M2 integers, the job processing times of each type "B" machine (1..20).

    SAMPLE INPUT (file job.in)

    5 2 3
    1 1 3 1 4
    

    OUTPUT FORMAT

    A single line containing two integers: the minimum time to perform all "A" tasks and the minimum time to perform all "B" tasks (which require "A" tasks, of course).

    SAMPLE OUTPUT (file job.out)

    3 5
    

    ——————————————————————————————————————

    假设A,B都获得了n个工件然后进行加工,我们通过循环判断哪个用时最少交给哪个,最后我们得到了A处理第1,2,3,4……工件所用的时间B处理第1,2,3,4工件所用的时间

    他们是一个递增的线段

    然后发现A用时最短的应该交给B用时最长的

     1 /*
     2 ID:ivorysi
     3 PROG:job
     4 LANG:C++
     5 */
     6 #include <iostream>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <queue>
    10 #include <set>
    11 #include <vector>
    12 #define inf 0x7fffffff
    13 #define ivorysi
    14 #define siji(i,x,y) for(int i=(x);i<=(y);++i)
    15 #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
    16 #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
    17 #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
    18 using namespace std;
    19 int n,m1,m2;
    20 int a[35],b[35],usea[35],useb[35];
    21 int spa[1005],spb[1005],ans;
    22 void init() {
    23     scanf("%d%d%d",&n,&m1,&m2);
    24     siji(i,1,m1) {
    25         scanf("%d",&a[i]);
    26     }
    27     siji(i,1,m2) {
    28         scanf("%d",&b[i]);
    29     }
    30 }
    31 void solve() {
    32     init();
    33     int mina,ida,minb,idb;
    34     siji(i,1,n) {
    35         mina=usea[1]+a[1];ida=1;
    36         minb=useb[1]+b[1];idb=1;
    37         siji(j,2,m1) {
    38             if(usea[j]+a[j]<mina) {
    39                 mina=usea[j]+a[j];
    40                 ida=j;
    41             }
    42         }
    43         siji(j,2,m2) {
    44             if(useb[j]+b[j]<minb) {
    45                 minb=useb[j]+b[j];
    46                 idb=j;
    47             }
    48         }
    49         usea[ida]=mina;
    50         useb[idb]=minb;
    51         spa[i]=mina;
    52         spb[i]=minb;
    53     }
    54     siji(i,1,n) {
    55         ans=max(ans,spa[i]+spb[n-i+1]);
    56     }
    57     printf("%d %d
    ",mina,ans);
    58 }
    59 int main(int argc, char const *argv[])
    60 {
    61 #ifdef ivorysi
    62     freopen("job.in","r",stdin);
    63     freopen("job.out","w",stdout);
    64 #else
    65     freopen("f1.in","r",stdin);
    66 #endif
    67     solve();
    68     return 0;
    69 }
  • 相关阅读:
    【转】 springBoot(5)---单元测试,全局异常
    【转】 springBoot(4)---热部署,配置文件使用
    【转】 springBoot(3)---目录结构,文件上传
    【转】 springBoot(2)---快速创建项目,初解jackson
    【转】 springBoot(1)---springboot初步理解
    【转】 SpringBoot+MyBatis+MySQL读写分离
    简单请求 vs 非简单请求
    H5新增的API
    图片
    vue更新dom的diff算法
  • 原文地址:https://www.cnblogs.com/ivorysi/p/6294441.html
Copyright © 2011-2022 走看看