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 题目大意: ...
随机推荐
- android开发,设置listview的高度无效
一般是在item的layout中设置高度 android:layout_height="100dp" 但是发现这样后无效,因此找到解决办法,如下: android:minHeigh ...
- 17、android设备如何防止屏幕休眠(转载)
当你需要你的设备需要长期运行时,由于移动设备为了延长电池续航时间,在运行15s-30mins后(用户可自由设置),如果用户在此时间段内没有操作,系统将进入休眠状态并 将屏幕锁上,所以在需要长期运行时, ...
- The income statement
The income statement measures performance over some period of time,usually a quarter or a year.The ...
- 使用Fiddler
右键一个Result,点击Inspect in new Window(Shift+Enter)
- 聊一聊js中的null、undefined与NaN
零.寒暄 翻翻自己的博客,上一篇竟然是六月26号的,说好的更新呢?回顾刚刚过去的这个七月,整天都是公司的入职培训加上自己的小论文,每天奋战到凌晨1点多,这是要挂的节奏啊!但是不论怎么说,自己的时间管理 ...
- GS线程
void GameServer::ProcessThread() { try {//在ui线程里面搞个大try不是说try效率不好吗,难道只是为了出现错误发现在GS线程里面出现的吗 ProcessTh ...
- websphere变成英文了
ebsphere页面怎么变成中文? 浏览器 -- internet选项 -- 常规 -- "语言" -- 打开后: 1. 如果只有"英语(美国)[en-US]" ...
- UML架构(转载)
任何真正的世界系统是由不同的用户使用.用户可以是开发人员,测试人员,商务人士,分析师和等等.所以在设计一个系统的体系结构是用不同的角度心态.最重要的部分是从不同的观看者的角度来看,以可视化的系统.我们 ...
- (链接保存)CentOS 6.6下yum快速升级内核
(因Docker建议3.8以上kernel版本)这个方法升级很方便,保存链接备用: http://www.dadclab.com/archives/5340.jiecao Docker Engine安 ...
- Unity上使用Linq To XML
using UnityEngine; using System.Collections; using System.Linq; using System.Xml.Linq; using System; ...