poj 1325 Machine Schedule 解题报告

题目链接:http://poj.org/problem?id=1325

题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1。每一个作业能运行在 A 的 某一个模式(假设为 i (0 <= i <= n-1 ) )或 B 的某一个模式下(j (0 <= j <= m-1))。多个作业可以同时运行在 A 的某一个 模式下,当然 B 也如此。每对A 或 B 转换一次模式,就要重启一次 A 或者 B,你需要选择A 或 B 的一些模式,使得所有 k 个 作业能够在最少重启次数下完成。

这题巧妙之处在于转化问题!题目说,所有 作业 都可以完成的,那么就不关 k 事了。某一个作业在 Ai 或者 Bj 模式下能够被完成,那么就在 Ai 和 Bj 这两点连一条边(map[Ai][Bj] =  1,注意先后顺序),那么问题就转化为 对于机器 A 所有的模式,找到 能与之匹配的 B 的 模式的最大匹配数。

其实这个是最小点覆盖问题啦,不过因为 最小点覆盖数 == 最大匹配数,所以继续匈牙利算法啦 ,网上很多证明,眼花缭乱,似懂非懂= =

不过确实转化得好巧妙~~~~~

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5
 6 const int maxk = 1000 + 5;
 7
 8 int vis[maxk], match[maxk];
 9 int map[maxk][maxk];
10 int n, m, k, cnt;
11
12 int dfs(int x)
13 {
14     for (int i = 1; i <= m; i++)
15     {
16         if (!vis[i] && map[x][i])
17         {
18             vis[i] = 1;
19             if (!match[i] || dfs(match[i]))
20             {
21                 match[i] = x;
22                 return 1;
23             }
24         }
25     }
26     return 0;
27 }
28
29 void Hungary()
30 {
31     cnt = 0;
32     for (int i = 1; i <= n; i++)   // 在 Ai 个模式下,找出对应的Bj,即match[Bj] = Ai
33     {
34         memset(vis, 0, sizeof(vis));
35         cnt += dfs(i);
36     }
37 }
38
39 int main()
40 {
41     while (scanf("%d", &n) != EOF && n)
42     {
43         scanf("%d%d", &m, &k);
44         int id, x, y;
45         memset(match, 0, sizeof(match));
46         memset(map, 0, sizeof(map));
47
48         for (int i = 1; i <= k; i++)
49         {
50             scanf("%d%d%d", &id, &x, &y);
51             map[x][y] = 1;
52         }
53         Hungary();
54         printf("%d\n", cnt);
55     }
56     return 0;
57 }

poj 1325 Machine Schedule 解题报告

时间: 2024-10-27 02:26:30

poj 1325 Machine Schedule 解题报告的相关文章

POJ 1325 Machine Schedule【最小点覆盖】

E - Machine Schedule Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1325 Appoint description:  System Crawler  (2014-08-10) Description As we all know, machine scheduling is a very classical pr

POJ 1325 Machine Schedule 二分图最大匹配

把每一个任务看做一个边,机器的模式看做是一个点,这个其实就是求一个最少点覆盖所有边即最小点覆盖集的问题,因为最小点覆盖集=二分图的最大匹配,所以问题转化成了求二分图最大匹配问题. 第一次写二分图匹配,感觉建模还是相当困难的. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <strin

POJ 1325 Machine Schedule (二分图最小点集覆盖 匈牙利算法)

Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12621   Accepted: 5399 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli

POJ 1325 Machine Schedule——S.B.S.

Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli

poj 1325 Machine Schedule 题解

Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14479   Accepted: 6172 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli

poj 1325 Machine Schedule 最小点覆盖

题目链接:http://poj.org/problem?id=1325 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 satis

POJ 1325 Machine Schedule(二分匹配 最小点覆盖)

题目链接:http://poj.org/problem?id=1325 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 m

POJ 1325 Machine Schedule (最小点覆盖 &amp;&amp; 二分图最大匹配)

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">鏈接: http://poj.org/problem?id=1325</span> Description As we all know, machine scheduling is a very classical problem in computer science a

ZOJ 1364 POJ 1325 -Machine Schedule

Time Limit:1000MS    Memory Limit:10000K 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 t