这道题考察对最小点覆盖的理解。

做法:

对于一个作业,它需要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 【二分图】的更多相关文章

  1. POJ - 1325 Machine Schedule 二分图 最小点覆盖

    题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式.假设要切换模式的话,机器就必须的重新启动 有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完 ...

  2. POJ 1325 Machine Schedule——S.B.S.

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 ...

  3. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  4. poj 1325 Machine Schedule 题解

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14479   Accepted: 6172 ...

  5. ZOJ 1364 Machine Schedule(二分图最大匹配)

    题意 机器调度问题 有两个机器A,B A有n种工作模式0...n-1 B有m种工作模式0...m-1 然后又k个任务要做 每一个任务能够用A机器的模式i或b机器的模式j来完毕 机器開始都处于模式0 每 ...

  6. HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)

    Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...

  7. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  8. poj 1325 Machine Schedule

    Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u   Java class name ...

  9. HDU1150 Machine Schedule(二分图最大匹配、最小点覆盖)

    As we all know, machine scheduling is a very classical problem in computer science and has been stud ...

随机推荐

  1. 浅谈maven中的scope,systempath

    scope  maven中scope的默认值是compile scope的分类 1)compile 默认是compile.compile表示被依赖项目需要参与当前项目的编译,包括后续的测试,运行周期也 ...

  2. JS BOM对象 History对象 Location对象

    一.BOM对象 BOM(浏览器对象模型),可以对浏览器窗口进行访问和操作 window对象 所有浏览器都支持 window 对象. 概念上讲.一个html文档对应一个window对象. 功能上讲: 控 ...

  3. 回归JavaScript基础(二)

    主题:在HTML中使用JavaScript. 要想把JavaScript放到网页中,就必须涉及到Web的核心语言HTML.向HTML页面中插入JavaScript的主要方法,就是使用<scrip ...

  4. Oracle EBS AR 更新客户组织层

    declare -- Local variables here i integer; g_module ) := 'TCA_V2_API'; lrec_org hz_party_v2pub.organ ...

  5. 【MySQL】无法启动mysql服务(位于本地计算机上)错误1067,进程意外中止

    好久没看MySQL了,今天启动起来找找感觉,尴尬了...发现服务启动不了.系统提示:无法启动mysql服务(位于本地计算机上)错误1067,进程意外中止. 解决过程: 1.在网上百度好久,看到一条解决 ...

  6. NodeJS做中转服务器,转发接口

    搬家后的博客地址:http://www.cnblogs.com/shihaibin821/p/7683752.html

  7. AFNetworking2.0简易GET,POST请求封装以及使用

    AFNetworking2.0简易GET,POST请求封装以及使用 AFNetworking不用我赘述其强大性,本人仅仅做了非常简易的封装,解决了有时候请求出错的问题,提供源码给大家. 封装源码库下载 ...

  8. Redis学习---Ubuntu下Redis的安装

    Ubuntu系统安装 Linux 系统安装[Ubuntu] 安装/启动Redis 要在 Ubuntu 上安装 Redis,打开终端,然后输入以下命令: 升级软件管理模块apt: sudo apt-ge ...

  9. September 02nd 2017 Week 35th Saturday

    Some things are more precious because they don't last long. 有些东西之所以弥足珍贵,是因为它们总是昙花一现. Life is ephemer ...

  10. [微信小程序直播平台开发]___(二)Nginx+rtmp在Windows中的搭建

    1.一个可以忽略的前言 Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Ramble ...