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 的 模式的最大匹配数。
其实这个是最小点覆盖问题啦,不过因为 最小点覆盖数 == 最大匹配数,所以继续匈牙利算法啦 ,网上很多证明,眼花缭乱,似懂非懂= =
不过确实转化得好巧妙~~~~~
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxk = + ; int vis[maxk], match[maxk];
int map[maxk][maxk];
int n, m, k, cnt; int dfs(int x)
{
for (int i = ; i <= m; i++)
{
if (!vis[i] && map[x][i])
{
vis[i] = ;
if (!match[i] || dfs(match[i]))
{
match[i] = x;
return ;
}
}
}
return ;
} void Hungary()
{
cnt = ;
for (int i = ; i <= n; i++) // 在 Ai 个模式下,找出对应的Bj,即match[Bj] = Ai
{
memset(vis, , sizeof(vis));
cnt += dfs(i);
}
} int main()
{
while (scanf("%d", &n) != EOF && n)
{
scanf("%d%d", &m, &k);
int id, x, y;
memset(match, , sizeof(match));
memset(map, , sizeof(map)); for (int i = ; i <= k; i++)
{
scanf("%d%d%d", &id, &x, &y);
map[x][y] = ;
}
Hungary();
printf("%d\n", cnt);
}
return ;
}
poj 1325 Machine Schedule 解题报告的更多相关文章
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)
Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...
- poj 1325 Machine Schedule 题解
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14479 Accepted: 6172 ...
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- poj 1325 Machine Schedule
Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class name ...
- POJ 1325 Machine Schedule(最小点覆盖)
http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...
- POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
随机推荐
- chromedriver错误信息提示
The open chrome driver window displays: Starting ChromeDriver (v2.8.241075) on port 10820 [8804:7492 ...
- C语言函数调用及栈帧结构
source:http://blog.csdn.net/qq_29403077/article/details/53205010 一.地址空间与物理内存 (1)地址空间与物理内存是两个完全不同的概念, ...
- iOS7中Cell高度 Label高度自适应
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSStr ...
- ajax 提交数组,mybatis 数组接受
function jinxingzhong() { // 配送单编号:psd2017090103 var divHtml = ""; $.ajax({ type: "PO ...
- SGU104 二维dp
大致题意: n个东西放在(1.2.3...m)个容器中,先放的必需在后方的左边.a[i][j]表示i号物品放在j容器所得 的价值,求最大价值. 几乎是刚刚开始接触动态规划题,开始我这样想 每个东西一件 ...
- grafana 安装 和 Nginx 、EL 联调
https://blog.csdn.net/u010735147/article/details/80943593
- 解决filter拦截request中body内容后,字符流关闭,无法传到controller的问题
解决filter拦截request中body内容后,字符流关闭,无法传到controller的问题 2.问题: 在一般的请求中,content-type为:application/x-www-form ...
- IOS UIPickView+sqlite 选择中国全部城市案例
1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...
- android项目笔记(一)
1.getInstance:单例模式创建类的实例,getInstance在单例模式(保证一个类仅有一个实例,并提供一个访问它的全局访问点)的类中常见,用来生成唯一的实例,getInstance往往是s ...
- jquery 获取下拉框 某个text='xxx'的option的属性 非选中 如何获得select被选中option的value和text和......
jquery 获取下拉框 某个text='xxx'的option的属性 非选中 5 jquery 获取下拉框 text='1'的 option 的value 属性值 我写的var t= $(" ...