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模式完 ...
随机推荐
- 洛谷 [P2485] 计算器
快速幂+同余方程+BSGS 同余方程在解的时候要注意,在将exgcd求出的解变换为原方程的解的时候,要取模 BSGS的原理就是用分块+hash优化暴力,要注意特判 a 和 b 是 p 的倍数的时候. ...
- Codeforces Round #265 (Div. 2) C 暴力+ 找规律+ 贪心
C. No to Palindromes! time limit per test 1 second memory limit per test 256 megabytes input standar ...
- PatentTips - Optimizing Write Combining Performance
BACKGROUND OF THE INVENTION The use of a cache memory with a processor facilitates the reduction of ...
- 标准C程序设计七---12
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- 快速掌握RabbitMQ(一)——RabbitMQ的基本概念、安装和C#驱动
1 RabbitMQ简介 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现,官网地址:http://www.rabbitmq.com.Ra ...
- 洛谷——P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- Execption异常 手动和自动抛除异常
package cn.zmh.Exception; /* * * try{ * 需要被检测的语句 * } * catch(异常类 变量){ * 异常的处理语句 * } * finally{ * 一定会 ...
- android应用开发之View的大小计量单位(px、dpi、dp、dip、sp)
http://blog.csdn.net/ljianhui/article/details/43601495?ref=myread 一.像素(px)与屏幕分辨率 1)px(Pixels ,像素):对应 ...
- js创建post请求
/**js提交post请求:隐藏请求参数**/function postDetail(URL, PARAMTERS) { //创建form表单 var temp_form = document.cre ...
- android 获得电池状态
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...