POJ 1235 Machine Schedule 【二分图】
这道题考察对最小点覆盖的理解。
做法:
对于一个作业,它需要A的a模式和B的b模式,那么可以从a模式向b模式连一条边;可以感性的理解为每一条边就是一个作业,需要求得有多少个模式可以覆盖所有的边,也就是最小点覆盖,也就是最大匹配。
注意 :
由于A,B的机器初始模式为0,那么所有的可以用模式0完成的工作都可以不用更换模式而完成!所以我们只需要考虑完成模式不包含0的作业。
AC代码:
#include <vector>
#include <cstdio>
#include <cstring> const int N = + ; std :: vector < int > g [ N ] ;
int link [ N ] , n , k , m , ans , x , a , b ;
bool vis [ N ] ; void create ( int u , int v ) {
g [ u ] . push_back ( v ) ;
} bool find ( int x ) {
int v ;
for ( int i = ; i < g [ x ] . size ( ) ; i ++ ) {
v = g [ x ] [ i ] ;
if ( ! vis [ v ] ) {
vis [ v ] = true ;
if ( ( ! link [ v ] ) || find ( link [ v ] ) ) {
link [ v ] = x ;
return true ;
}
}
}
return false ;
} void init ( ) {
memset ( link , , sizeof ( link ) ) ;
ans = ;
} int main ( ) { // 待调试
while ( ) {
scanf ( "%d" , & n ) ;
if ( n == ) return ;
scanf ( "%d%d" , & m , & k ) ;
init ( ) ;
// A : 1 ~ n ;
// B : n + 1 ~ n + m ;
for ( int i = ; i <= k ; i ++ ) {
scanf ( "%d%d%d" , & x , & a , & b ) ;
if ( a * b != ) create ( a , b + n ) ;
}
for ( int i = ; i <= n ; i ++ ) {
memset ( vis , false , sizeof ( vis ) ) ;
if ( find ( i ) )
ans ++ ;
}
printf ( "%d\n" , ans ) ;
for ( int i = ; i <= n + m ; i ++ )
g [ i ] . clear ( ) ;
}
}
AC
POJ 1235 Machine Schedule 【二分图】的更多相关文章
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...
- POJ 1325 Machine Schedule——S.B.S.
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13731 Accepted: 5873 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- poj 1325 Machine Schedule 题解
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14479 Accepted: 6172 ...
- ZOJ 1364 Machine Schedule(二分图最大匹配)
题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...
- 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 ...
- HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)
As we all know, machine scheduling is a very classical problem in computer science and has been stud ...
随机推荐
- Windows远程桌面Debian配置
由于xrdp.gnome和unity之间的兼容性问题,在Debian仍然无法使用xrdp登陆gnome或unity的远程桌面,现象是登录后只有黑白点为背景,无图标也无法操作.使用xrdp只能登录xfc ...
- 1 Java程序文件中函数起始行和终止行在程序文件位置中的判定__抽象语法树方法
应用需求: 实现对BigCloneBench中函数体的克隆检测,必须标注出起始行号和终止行号. 问题: 给定一个Java文件,从中提取出每个函数的起始行和终止行. 难点: 这个问题的难点在于,对于Ja ...
- Vue2学习笔记:数据交互vue-resource
基本语法 必须引入一个库:vue-resource github地址 // 基于全局Vue对象使用http Vue.http.get('/someUrl', [options]).then(succe ...
- IP地址分类及CIDR划分方法
IP地址的分类和表示有三种形式,1.分类的IP地址.2.子网划分.3.无分类编址CIDR 1.分类的IP地址 IP地址:: = {<网络号>,<主机号>} 不同的网络号和主机号 ...
- Ubuntu16.04安装redis和php的redis扩展
安装redis服务 sudo apt-get install redis-server 装好之后默认就是自启动.后台运行的,无需过多设置,安装目录应该是 /etc/redis 启动 sudo ser ...
- Office 365 Pass-through身份验证及Seamless Single Sign-On
Hello 小伙伴们, 这篇文章将视点聚焦在传递身份验证(Pass-through Authentication)上,将分享如何安装,配置和测试Azure Active Directory(Azure ...
- hibernate连接mysql,查询条件中有中文时,查询结果没有记录,而数据库有符合条件的记录(解决方法)
今天在另一台服务器上重新部署了网站,结果出现了以下问题: ——用hibernate做mysql的数据库连接时,当查询条件中有中文的时候,查询结果没有记录,而数据库中是存在符合条件的记录的. 测试了以下 ...
- TreeSet集合的add()方法源码解析(01.Integer自然排序)
>TreeSet集合使用实例 >TreeSet集合的红黑树 存储与取出(图) >TreeSet的add()方法源码 TreeSet集合使用实例 package cn.itca ...
- September 28th 2017 Week 39th Thursday
Every saint has a past and every sinner has a future. 圣人皆有过去,罪人皆有未来. If you were a sinner in the pas ...
- 题解 P1018 【乘积最大】
题目链接:P1018 乘积最大 题面 今年是国际数学联盟确定的"2000――世界数学年",又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面 ...