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 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种模式(0~n-1),B机器有m种模式(0~m-1),目前AB机器都处于模式0。给出k个工作,每个工作要么使机器A改变模式为i,要么使机器B改变模式为j。机器每次改变模式都需要重启一次,问k个工作完成之后,最少的重启次数。
算法分析:首先知道这是一个二分图。
给出这样一组数据:k=n=m=3
工作1可以改变A为1,改变B为2;工作2改变A为1,改变B为1;工作3改变A为1,改变B为0。
那么我们只需要一次重启就可以了:把A从0改变为1。
于是就想到了这道题可以用最小点覆盖来做。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+; int n,m,k;
int g[maxn][maxn],linker[maxn];
int vis[maxn]; int dfs(int u)
{
for (int v= ;v<m ;v++) if (g[u][v])
{
if (!vis[v])
{
vis[v]=;
if (linker[v]==- || dfs(linker[v]))
{
linker[v]=u;
return ;
}
}
}
return ;
} int hungary()
{
int ans=;
for (int i= ;i<n ;i++)
{
memset(vis,,sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
} int main()
{
while (scanf("%d",&n)!=EOF && n)
{
scanf("%d%d",&m,&k);
memset(g,,sizeof(g));
memset(linker,-,sizeof(linker));
g[][]=;
int j,a,b;
while (k--)
{
scanf("%d%d%d",&j,&a,&b);
g[a][b]=;
}
printf("%d\n",hungary());
}
return ;
}
poj 1325 Machine Schedule 最小点覆盖的更多相关文章
- POJ 1325 Machine Schedule(最小点覆盖)
http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...
- 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 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- 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,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- 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 题解
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14479 Accepted: 6172 ...
- poj 1325 Machine Schedule 解题报告
题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...
随机推荐
- ES2015 ——let命令的暂时性死区
ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. 和var不同的还有,let命令不存在变量提升,所以声明前调用变量,都会报错,这就涉及到 ...
- C# 验证IP是否正确简易方法 源代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- linux之i2c子系统架构---总线驱动
编写i2c设备驱动(从设备)一般有两种方式: 1.用户自己编写独立的从设备驱动,应用程序直接使用即可. 2.linux内核内部已经实现了一个通用的设备驱动,利用通用设备驱动编写一个应用程序(用户态驱动 ...
- java解析XML几种方式
第一种:DOM. DOM的全称是Document Object Model,也即文档对象模型.在应用程序中,基于DOM的XML分析器将一个XML文档转换成一个对象模型的集合(通常称DOM树),应用程序 ...
- oracle11g rman验证备份有效性
RMAN> restore validate controlfile; Starting restore at 21-NOV-13using target database control fi ...
- Objective-C编码规范
参考 http://www.csdn.net/article/2015-06-01/2824818-objective-c-style-guide/1 介绍 我们制定Objective-C编码规范的原 ...
- iOS 开发者能用上的 10 个 Xcode 插件
本文由 伯乐在线 - 邢敏 翻译,黄利民 校稿.未经许可,禁止转载! 英文出处:code.tutsplus.com.欢迎加入翻译小组. 1. XcodeColors:给 Xcode 控制台添加颜色 2 ...
- MVC 中的@Html.DropDownList下拉框的使用
MVC 中的下拉框 实现方式,下面为大家介绍一个我自己认为比较好用的实现方式,而二话不说直接上代码: 第一步: 后台代码 //公共的方法 //在每次需要展示下拉框的时候,需要调用一下这个方法 [数据源 ...
- openSUSE install failed
install openSUSE 13.1 with vmware play (version 6.0.0) calling the yast module 'inst_autoinit has f ...
- JS如何获取多个相同class标签并分别再输出各自的文本
function getClass(boo) { var span = $("span.w");//获取所有的span标签 <span class="w" ...