POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
题意:
有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成。问最少要给机器A,B调多少次模式可以完成任务。
思路:
相当于是在以n、m个点构成的二分图中,求二分图的最小顶点覆盖数(就是每个任务都涉及到,所需的顶点数)。根据Konig定理,二分图的最小顶点覆盖数就是求最大匹配数,注意这里是Base 0的,就是初始不用调整模式就可以完成0模式的任务,所以读入的时候不用考虑与0相连的边。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------showtime----------------------*/
const int maxn = 1e5+;
struct edge{
int v,nx;
}e[maxn];
int h[maxn],tot = ;
void addedge(int u,int v){
e[tot].v = v;
e[tot].nx = h[u];
h[u] = tot++;
}
int mx[maxn],my[maxn],vis[maxn];
bool dfs(int x){ for(int i = h[x]; ~i; i = e[i].nx){
int v = e[i].v; if(vis[v]==){
vis[v] = ;
if(mx[v]==-||dfs(mx[v])){
mx[v] = x;
my[x] = v;
return true;
}
}
}
return false;
}
int main(){
int n,m,k;
while(~scanf("%d", &n) && n){
tot = ;
memset(h,-,sizeof(h));
memset(mx,-,sizeof(mx));
memset(my,-,sizeof(my)); scanf("%d%d", &m, &k);
for(int i=; i<=k; i++){
int u,v,q;
scanf("%d%d%d", &q, &u, &v);
if(u*v)addedge(u,v);
} int ans = ;
for(int i=; i<n; i++){
memset(vis,,sizeof(vis));
if(dfs(i))ans++;
}
printf("%d\n", ans);
}
return ;
}
POJ1325
POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题的更多相关文章
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- 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 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- 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
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 ...
随机推荐
- C语言编程入门之--第四章C语言基本数据类型
导读:C语言程序中经常涉及一些数学计算,所以要熟悉其基本的数据类型.数据类型学习起来比较枯燥,不过结合之前的内存概念,以及本节的字节概念,相信数据类型也就不难理解了.本章从二进制的基本概念开始,然 ...
- 基于zookeeper集群的云平台-配置中心的功能设计
最近准备找工作面试,就研究了下基于zookeeper集群的配置中心. 下面是自己设想的关于开源的基于zookeeper集群的云平台-配置中心的功能设计.大家觉得哪里有问题,请提出宝贵的意见和建议,谢谢 ...
- apache bench的简单使用
ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求. 需要针对web做压力测试,所以简单学习了一 ...
- python3 编译安装
前言: Linux下大部分系统默认自带python2.x的版本,最常见的是python2.6或python2.7版本,默认的python被系统很多程序所依赖,比如centos下的yum就是python ...
- JS和C#.NET获取客户端IP
我们经常在项目中会遇到这种需要获取客户端真实IP的需求,其实在网上也能随便就能查到各种获取的方法,我也是在网上查了加上了自己的实践,说一下自己在实践后的感受,基本上网上大部分都是用JS的方法来获取客户 ...
- 【Java例题】8.1手工编写加法器的可视化程序
1. 手工编写加法器的可视化程序. 一个Frame窗体容器,布局为null,三个TextField组件,一个Button组件. Button组件上添加ActionEvent事件监听器ActionLis ...
- [zz] pomelo windows 环境下开发环境搭建
原文链接:http://nodejs.netease.com/topic/515279a0b5a2705b5a000983 本文主要介绍下 windows 下跑通 pomelo 简单例子的过程 开发前 ...
- 剑指offer-链表
1. 链表中环的入口节点 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null. 思路一:用哈希表存已经遍历过的节点,O(1)复杂度查找,如果再次遇到就是环入口 # -*- cod ...
- Java学习|Exception和Error有什么区别?
典型回答: Exception和Error都继承了Throwable类,java中只有Throwable类型的实例才能被Throw(抛出)或者catch(捕获). Exceptio ...
- S3C2440 移植最新5.2linux内核
基于 移植uboot后. 1. 移植linux内核 1.1 下载源码 打开 https://www.kernel.org/ 直接肝最新的 5.2.8 下载完后,在ubuntu里解压备用. 1.2 搭建 ...