Krydom: 暁の水平线に胜利を刻むのです

ソロモンの悪夢、見せてあげる!

@krydom2年前

08/21
19:04
二分图匹配 最大流

Machine Schedule [poj 1325 zoj 1364]

00:00/00:00

大祭司 千秋万代 一统江湖! qwq qwq qwq

efa07f87e950352aab9ac3775543fbf2b3118baecf1f140fd9f9d72a3dcef662d22a2834359bbbff964528224f4a20a40eb4dab896529822730ed0ff

♦♦♦♦♦♦   Description   ♦♦♦♦♦♦

    As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, ..., mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, ... , mode_m-1. At the beginning they are both work at mode_0.

For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.

Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.

众所周知,机器调度是计算机科学中非常典型的一个问题,已经被研究很长时间了。各种机器调度问题在一下方面差别很大:必须满足的约束条件,以及期望得到的调度时间表。现在考虑一个针对两台机器的机器调度问题。

假设有两台机器,A和B。机器A有n种工作模式,分别称为mode_0,mode_1,...,mode_n-1。同时机器B有m种工作模式,分别为mode_0,mode_1,...,mode_m-1.刚开始时,A和B都工作在模式mode_0.

给定K个作业,每个作业可以工作在任何一个机器的特定模式下。例如,作业0可以工作在机器A的模式mode_3或者机器B的mode_4模式;作业1可以工作在机器A的模式mode_2或者工作在机器B的模式mode_4等。因此,对于工作j,调度中的约束条件可以表述成一个三元组(i,x,y),意思是工作i可以在机器A的mode_x模式或者机器B的mode_y模式。

很显然的是,为了完成所有的作业,必须时不时切换机器的工作模式,但不幸的是,机器工作模式的切换只能通过手动重启机器完成。试编写程序实现:改变机器的顺序,给每个作业分配合适的作业,使得重启机器的次数最少。

 

♦♦♦♦♦♦   Input   ♦♦♦♦♦♦

The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y.

      The input will be terminated by a line containing a single zero.

   输入文件包含多个测试数据,每个测试数据的第一行为3个整数:n,m和k,其中n,m<100,k<1000,。接下来有k行给出了k个作业的约束,每一行为一个三元组:i,x,y。

输入文件的最后一行为一个0,表示输入结束。

♦♦♦♦♦♦   Output   ♦♦♦♦♦♦

The output should be one integer per line, which means the minimal times of restarting machine.

   对输入文件中的每个测试数据,输出一行,为一个整数,表示需要重启机器的最少次数。

♦♦♦♦♦♦   Sample Input   ♦♦♦♦♦♦

5 5 10

0 1 1

1 1 2

2 1 3

3 1 4

4 2 1

5 2 2

6 2 3

7 2 4

8 3 3

9 4 3

0

♦♦♦♦♦♦   Sample Output   ♦♦♦♦♦♦

3

♦♦♦♦♦♦   Hint   ♦♦♦♦♦♦

n,m<100,k<1000

♦♦♦♦♦♦   题解  ♦♦♦♦♦♦

首先构造二分图:把A的n个mode和B的m个mode看作图的顶点,如果某个人物可以在A的mode_i或B的mode_j上完成,则Ai到Bj连接一条边,这样构造了一个二分图。

    本题要求二分图的最小点覆盖集问题,即求最小的顶点集合,“覆盖”住所有的边。转换成求二分图的最大匹配问题。

    另外,机器A和机器B最初工作在模式_0,所以对于那些可以工作在机器A的模式_0或者机器B的模式_0的作业,在完成这些工作时是不需要重启机器的。

5c3acdff9925bc3147d0e8e458df8db1ca137009

 

Machine Schedule [poj 1325 zoj 1364]