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。每个操作只有一些机器能够完成。

上图显示了按照下述方式工作的流水线的组织形式。A型机器从输入库接受工件,对其施加操作A,得到的中间产品存放在缓冲库。B型机器从缓冲库接受中间产品,对其施加操作B,得到的最终产品存放在输出库。所有的机器平行并且独立地工作,每个库的容量没有限制。每台机器的工作效率可能不同,一台机器完成一次操作需要一定的时间。

给出每台机器完成一次操作的时间,计算完成A操作的时间总和的最小值,和完成B操作的时间总和的最小值。

[编辑]格式

PROGRAM NAME: job

INPUT FORMAT:

(file job.in)

第一行 三个用空格分开的整数:N,工件数量 (1<=N<=1000);M1,A型机器的数量 (1<=M1<=30);M2,B型机器的数量 (1<=M2<=30)。

第二行…等 M1个整数(表示A型机器完成一次操作的时间,1..20),接着是M2个整数(B型机器完成一次操作的时间,1..20)

OUTPUT FORMAT:

(file job.out)

只有一行。输出两个整数:完成所有A操作的时间总和的最小值,和完成所有B操作的时间总和的最小值(A操作必须在B操作之前完成)。

[编辑]SAMPLE
INPUT

5 2 3
1 1 3 1 4

[编辑]SAMPLE
OUTPUT

3 5

开始还很怕这种贪心的题目,感觉需要很多数学的证明。今天研究了一下,其实也并不是很难。

第一问很好解决。我们枚举每台机子的状态,寻找当前第i个产品放在哪里更快,并同时更新机器和商品的时间。等所有商品都枚举好后,选一个时间最大的即可。(当然是最后一个处理的商品)

后来的B机器也可以同上述方法过。但是我们会发现,B机器是直接和A机器相关的,于是我们不能光把B机器处理产品的最大时间输出。那么我们贪心地想一想:在A机器处理好后的产品中,速度快的一些我放在B机器中处理慢的地方。这样才能使时间更均衡。因此第二问的答案就是max(time1[i]+time2[n-i+1])(其中time1和time2分别是第i快的产品在A,B机器里操作的时间)

代码:

/*
PROG:job
ID:juan1973
LANG:C++
*/
#include<stdio.h>
using namespace std;
const int maxn1=1001;const int maxn2=31;const int INF=2000000000;
int na,nb,n,i,j,min,ans,k;
int time1[maxn1],time2[maxn1],timea[maxn2],timeb[maxn2],a[maxn2],b[maxn2];
int main()
{
    freopen("job.in","r",stdin);
    freopen("job.out","w",stdout);
    scanf("%ld%ld%ld",&n,&na,&nb);
    for (i=1;i<=na;i++) scanf("%ld",&a[i]);
    for (i=1;i<=nb;i++) scanf("%ld",&b[i]);
    for (i=1;i<=n;i++)
    {
      min=INF;
      for (j=1;j<=na;j++)
        if (timea[j]+a[j]<min) {min=timea[j]+a[j];k=j;}
      timea[k]=time1[i]=min;
    }
    printf("%ld ",min);
    for (i=1;i<=n;i++)
    {
      min=INF;
      for (j=1;j<=nb;j++)
        if (timeb[j]+b[j]<min) {min=timeb[j]+b[j];k=j;}
      timeb[k]=time2[i]=min;
    }
    ans=0;
    for (i=1;i<=n;i++)
      if (time1[i]+time2[n-i+1]>ans) ans=time1[i]+time2[n-i+1];
    printf("%ld\n",ans);
    //scanf("%ld",&n,&na,&nb);
    return 0;
}

usaco training 4.2.3 Job Processing 题解的更多相关文章

  1. usaco training 4.1.2 Fence Rails 题解

    Fence Rails题解 Burch, Kolstad, and Schrijvers Farmer John is trying to erect a fence around part of h ...

  2. 关于USACO Training

    做了这么久的题目,突然发现最经典的 USACO Training 还没有做过?加速水一遍吧!我会把题解放在上面的.

  3. USACO Training Section 1.1 坏掉的项链Broken Necklace

    题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的. 这里是 n=29 的二个例子: 第一和第二个珠子在图片中已经被作记号. 图片 A ...

  4. USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers

    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...

  5. USACO Training Section 1.1 Your Ride Is Here

    题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...

  6. USACO Training Section 1.2 双重回文数 Dual Palindrom

    题目描述 如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做"回文数".例如,12321就是一个回文数,而77778就不是.当然,回文数的首和尾都应是非零的,因此0220就 ...

  7. usaco training 3.4.3 fence9 题解

    Electric Fence题解 Don Piele In this problem, `lattice points' in the plane are points with integer co ...

  8. usaco training 4.2.4 Cowcycles 题解

    Cowcycles题解 Originally by Don Gillies [International readers should note that some words are puns on ...

  9. usaco training 4.2.2 The Perfect Stall 最佳牛栏 题解

    The Perfect Stall题解 Hal Burch Farmer John completed his new barn just last week, complete with all t ...

随机推荐

  1. Swift 入门之简单语法(一)

    定义 let 定义常量,一经赋值不允许再修改 var 定义变量,赋值之后仍然可以修改 //: # 常量 //: 定义常量并且直接设置数值 let x = 20 //: 常量数值一经设置,不能修改,以下 ...

  2. Neo4j 第五篇:批量更新数据

    相比图形数据的查询,Neo4j更新图形数据的速度较慢,通常情况下,Neo4j更新数据的工作流程是:每次数据更新都会执行一次数据库连接,打开一个事务,在事务中更新数据.当数据量非常大时,这种做法非常耗时 ...

  3. C# 通过 oledb 操作Excel

    public string GetConnectionString()         {             Dictionary<string, string> props = n ...

  4. python基础入门教程《python入门经典》

    第一章 在python中使用数字 1.用变量存储信息 1.1变量的类型 变量,用于存储很多不同的数据类型的信息. 基本数据类型 数据类型 存储内容 示例 integer 整   float 浮点   ...

  5. js for循环 等腰三角形demo

    <script> for(var i=1;i<10;i++){ for(var j=1;j<10-i;j++){document.write(" ")} f ...

  6. ThinkPHP3.2 生成二维码

    下面是整合将phpqrcode整合到TP生成二维码就可以解决这个问题了.其实也很简单,使用方法如下:先下载附件解压至ThinkPHP/Extend/Vendor目录,目录不存在自己创建.      v ...

  7. python 标准库 -- re

    re 正则表达式 语法 import re m = re.search('[0-9]','abc4def67') # 匹配字符及匹配范围 print m.group(0) # 返回匹配结果 re.se ...

  8. 深入浅出HTTP协议

    超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的是为了提供一种发布和接 ...

  9. RabbitMQ系列教程之三:发布/订阅(Publish/Subscribe)

    (本教程是使用Net客户端,也就是针对微软技术平台的)   在前一个教程中,我们创建了一个工作队列.工作队列背后的假设是每个任务会被交付给一个[工人].在这一部分我们将做一些完全不同的事情--我们将向 ...

  10. 关于MATLAB处理大数据坐标文件2017526

    运行六个特征,提高了3分,也就是说以前做的特征已经用完了,穷途末路,依靠以前的特征已经很难取得进步了,提出以下建议 1.测试集曾经运行错误的数据尽早画出图形,并尽可能发现问题并提出特征 2.运行其他程 ...