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 ...
随机推荐
- python对数据去重处理
我们在数据处理时,经常需要用到对重复数据进行过滤处理. 对数据去重有两种处理方式,如下: 1.对重复数据去重,并且会自动排序 使用函数 set # 列表去重 list_a = [6, 6, 5, ...
- GC是什么?为什么我们要去使用它
GC(Garbage Collection)是各大语言的宠儿,也是计算机科学领域里很热门的一个话题.最早在JVM中有看过这个算法,后来发现即使是js这种脚本语言也是有GC的.单纯就JVM来说的话,GC ...
- 后端小白的VUE入门笔记, 前端高能慎入
因为项目需要前后端分离,后端竟然不用控制view层了,页面的跳转后端不再干涉,(前端的vue经过打包后成了一张index.html) 后端只需要响应给前端json串就ok,其实这不是爽歪歪?但是觉得还 ...
- 拉格朗日对偶性(Lagrange duality)
目录 拉格朗日对偶性(Lagrange duality) 1. 从原始问题到对偶问题 2. 弱对偶与强对偶 3. KKT条件 Reference: 拉格朗日对偶性(Lagrange duality) ...
- S2:类的构造函数
类的构造函数构造函数名与类名形同,不返回任何值,主要完成对象的初始化工作. (1)在构造函数中,可以给属性设置默认值(2)this只带当前对象 (3)如果不给属性赋初始值,则会以默认值来填充.(4)如 ...
- CentOS7 安装 单机 Mysql
1.解压文件 [root@centos3 ~]# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ 2.重命名 [ ...
- 两个 github 账号混用,一个帐号提交错误
问题是这样,之前有一个github帐号,因为注册邮箱的原因,不打算继续使用了,换了一个新的邮箱注册了一个新的邮箱帐号.新账号提交 就会出现下图的问题,但是原来帐号的库还是能正常提交. 方法1:添加 ...
- Redis简单梳理及集群配置
**REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C语言编写.遵 ...
- Flink 源码解析 —— Flink JobManager 有什么作用?
JobManager 的作用 https://t.zsxq.com/2VRrbuf 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac ...
- AutoCAD二次开发(.Net)之创建图层Layer
//https://blog.csdn.net/qq_21489689?t=1[CommandMethod("CREATELY")] public void CreateLayer ...