poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数.
===================================================
对于任务(i,x,y),我们在A机mode_x与B机mode_y之间连一条边.这样,题目就变成了一个二分图,我们的目的是完成所有任务,即覆盖所有线段,题目要求选择最少的点,使得每个线段至少有一个端点被选中(这个任务就被完成了),这就是最小点覆盖模型,答案是这个二分图的最大匹配.
但是这题我是用最大流水过的,可以增加一个超级源点和超级汇点分别和A,B机器的每个模式连一条边权为一的边,然后就是最大流了
注意起始时,机器都处在模式0!!
for(int i=0;i<k;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(b*c!=0)
map[b][c]=true;
}
下面是我的代码
/*********
PRO: POJ 1325
TIT: Machine Schedule
DAT: 2013-08-16-15.50
AUT: UKean
EMA: huyocan@163.com
*********/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define INF 1e9
using namespace std;
queue<int> que;//广搜需要使用的队列
int s,t;//源点和汇点
int flow[505][505];//残流量
int p[505];//广搜记录路径的父节点数组
int a[505];//路径上的最小残量
int cap[505][505];//容量网络
int ans;//最大流
int read()
{
int n,m,k;
cin>>n;if(!n) return 0;
cin>>m>>k;
s=0;t=m+n+1;
//1->n 是A n+1 ->n+m是B
memset(cap,0,sizeof(cap));
for(int i=0;i<k;i++)
{
int a,b,c;cin>>a>>b>>c;
if(b*c!=0)//记住初始状态为0 0 所以只要b或c中有一个为0,那么就不用把它存入图中了
cap[b+1][c+n+1]=1;
}
for(int i=1;i<=n;i++)
cap[s][i]=1;
for(int i=n+1;i<=n+m;i++)
cap[i][t]=1;
return 1;
}
int deal()//增广路算法就不具体解释了,详细的解释可以看我关于网络流的第一篇博客
// http://blog.csdn.net/hikean/article/details/9918093
{
memset(flow,0,sizeof(flow));
ans=0;
while(1)
{
memset(a,0,sizeof(a));
a[s]=INF;
que.push(s);
while(!que.empty())
{
int u=que.front();que.pop();
for(int v=0;v<=t;v++)
if(!a[v]&&cap[u][v]-flow[u][v]>0)
{
p[v]=u;
que.push(v);
a[v]=min(a[u],cap[u][v]-flow[u][v]);//路径上的最小残流量
}
}
if(a[t]==0) break;
for(int u=t;u!=s;u=p[u])
{
flow[p[u]][u]+=a[t];
flow[u][p[u]]-=a[t];
}
ans+=a[t];
}
cout<<ans<<endl;
return ans;
}
int main()
{
while(read())
deal();
return 0;
}
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 题解
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14479 Accepted: 6172 ...
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 最小点覆盖
题目链接: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 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 ...
- 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 题目大意: ...
随机推荐
- git学习,什么是git?
什么是 Git? 百度百科显示,Git是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的,被认为是分布式版本控制工具中的顶级水准.智能.友好.强健.高效. 正如所 ...
- hibernate---ID生成策略
5.1.4.1. Generator 可选的<generator>子元素是一个Java类的名字, 用来为该持久化类的实例生成唯一的标识.如果这个生成器实例需要某些配置值或者初始化参数, 用 ...
- 02.Redis主从集群的Sentinel配置
1.集群环境 1.Linux服务器列表 使用4台CentOS Linux服务器搭建环境,其IP地址如下: 192.168.110.100 192.168.110.101 192.168.110.102 ...
- Java多jdk安装
1.安装jdk 2.配置 1.安装(略) 2.配置 2.1 regedit 注册表修改,假定已经安装jdk1.6,现在更换为jdk1.7 注: 修改红色框中CurrentVersion为jdk1.7 ...
- 【BZOJ】【2084】【POI2010】Antisymmetry
Manacher算法 啊……Manacher修改一下就好啦~蛮水的…… Manacher原本是找首尾相同的子串,即回文串,我们这里是要找对应位置不同的“反回文串”(反对称?233) 长度为奇数的肯定不 ...
- BZOJ2694: Lcm
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2694 题解:令f[i]表示i是否有平方因子,则f[i]是积性函数,mu[i]表示莫比乌斯函数. ...
- [geeksforgeeks] Bottom View of a Binary Tree
http://www.geeksforgeeks.org/bottom-view-binary-tree/ Bottom View of a Binary Tree Given a Binary Tr ...
- .NET中JSON的序列化和反序列化
.NET 中有两种方法进行JSON的操作分别需要引用不同的命名空间 1.System.Runtime.Serialization.Json(System.Runtime.Serialization.d ...
- Full GC有关问题学习分析(转载)
网站持久代引发Full GC问题分析 现状: Dragoon(监控系统)的日报显示trade_us_wholelsale(美国wholesale集群),日均Young GC次数25w次左右,应用暂停2 ...
- 使用Visio进行UML建模
http://www.qdgw.edu.cn/zhuantiweb/jpkc/2009/rjkf/xmwd/Visio_UmlModel.htm#_Toc80417837 内容提纲: 1.VISIO中 ...