问题:POJ2446

分析:

  采用黑白相间的方法把棋盘分成两个点集,是否可以用1*2的卡片实现全覆盖等价于二分图是否有完全匹配。

AC代码

 //Memory: 172K        Time: 32MS
 #include <iostream>
 #include <cstring>
 #include <cstdio>

 using namespace std;

  *  /  + ;
 ][];
 ];
 int ne[maxn];
 int match[maxn];
 int vis[maxn];
 int m, n, k;
 int x, y;
 int flag;
 int num1, num0;
 ][] = { {, }, {-, }, {, }, {, -}};

 bool findPath(int start)
 {
     ; i < ne[start]; i++){
         int current = edge[start][i];
         if ( vis[current] ) continue;
         vis[current] = ;
         if ( !match[current] || findPath( match[current] ) ){
             match[current] = start;
             return true;
         }
     }
     return false;
 }

 bool solve()
 {
     memset(match, , sizeof(match));
     ;
     ; i <= num0; i++){
         memset(vis, , sizeof(vis));
         if ( findPath(i) )
             ++cnt;
     }
     if (cnt == num0) return true;
     return false;
 }

 void input()
 {
     memset(edge, , sizeof(edge));
     memset(ne, , sizeof(ne));
     memset(maze, , sizeof(maze));
     scanf("%d%d%d", &m, &n, &k);
     ; i < k; i++){
         scanf("%d%d", &x, &y);
         maze[y - ][x - ] =  -;
     }
     num0 = num1 = ;
     ; i < m; i++)
         ; j < n; j++){
              && (i + j) %  == ) {
                 maze[i][j] = ++num0;
             }
              && (i + j) %  == ) {
                 maze[i][j] = ++num1;
             }
         }
     if ( num0 != num1 ) return;
     ; i < m; i++) {
         ; j < n; j++){
              ==  && maze[i][j] != -){
                 int current = maze[i][j];
                 ; k < ; k++){
                     ];
                     ];
                      || nj >= n || nj < )
                         continue;
                     ) edge[current][ne[current]++] = maze[ni][nj];
                 }
             }
         }
     }
 }

 int main()
 {
     input();
     if ( num0 == num1 && solve() ) printf("YES\n");
     else printf("NO\n");
     ;
 }

POJ2446 二分图最大匹配的更多相关文章

  1. [POJ2446] Chessboard(二分图最大匹配-匈牙利算法)

    传送门 把所有非障碍的相邻格子彼此连一条边,然后求二分图最大匹配,看 tot * 2 + k 是否等于 n * m 即可. 但是连边不能重复,比如 a 格子 和 b 格子 相邻,不能 a 连 b ,b ...

  2. POJ 2226二分图最大匹配

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...

  3. POJ2239 Selecting Courses(二分图最大匹配)

    题目链接 N节课,每节课在一个星期中的某一节,求最多能选几节课 好吧,想了半天没想出来,最后看了题解是二分图最大匹配,好弱 建图: 每节课 与 时间有一条边 #include <iostream ...

  4. poj 2239 二分图最大匹配,基础题

    1.poj 2239   Selecting Courses   二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...

  5. UESTC 919 SOUND OF DESTINY --二分图最大匹配+匈牙利算法

    二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). ...

  6. 二分图最大匹配的K&#246;nig定理及其证明

     二分图最大匹配的K?nig定理及其证明 本文将是这一系列里最短的一篇,因为我只打算把K?nig定理证了,其它的废话一概没有.    以下五个问题我可能会在以后的文章里说,如果你现在很想知道的话,网上 ...

  7. POJ3057 Evacuation(二分图最大匹配)

    人作X部:把门按时间拆点,作Y部:如果某人能在某个时间到达某门则连边.就是个二分图最大匹配. 时间可以二分枚举,或者直接从1枚举时间然后加新边在原来的基础上进行增广. 谨记:时间是个不可忽视的维度. ...

  8. ZOJ1654 Place the Robots(二分图最大匹配)

    最大匹配也叫最大边独立集,就是无向图中能取出两两不相邻的边的最大集合. 二分图最大匹配可以用最大流来解. 如果题目没有墙,那就是一道经典的二分图最大匹配问题: 把地图上的行和列分别作为点的X部和Y部, ...

  9. HDU:过山车(二分图最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意:有m个男,n个女,和 k 条边,求有多少对男女可以搭配. 思路:裸的二分图最大匹配,匈牙利算法. 枚 ...

随机推荐

  1. Python一路走来 线程 进程

    Python线程 Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #!/usr/bin/env pytho ...

  2. caffe绘制训练过程的loss和accuracy曲线

    转自:http://blog.csdn.net/u013078356/article/details/51154847 在caffe的训练过程中,大家难免想图形化自己的训练数据,以便更好的展示结果.如 ...

  3. cf E. Dima and Magic Guitar

    http://codeforces.com/contest/366/problem/E |x1-x2|+|y1-y2|有四种情况 1.-(x1-x2)+(y1-y2); 2.(x1-x2)-(y1-y ...

  4. GO不支持数组通过函数参数更改,有点不一样

    package main import "fmt" func modify(array []int) { array[] = fmt.Println("In modify ...

  5. LeetCode_Minimum Path Sum

    iven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  6. Qt Lite

    http://blog.qt.io/blog/2016/08/18/introducing-the-qt-lite-project-qt-for-any-platform-any-thing-any- ...

  7. Powershell Switch 条件

    Powershell Switch 条件 6 21 1月, 2012  在 Powershell tagged Powershell教程/ 分支/ 字符串/ 数字/ 条件by Mooser Lee 本 ...

  8. logstash tomcat catalina.out zabbix 插件不会引起崩溃

    input { file { type => "zj_api" path => ["/data01/applog_backup/zjzc_log/zj-api ...

  9. logstash 通过type判断

    [elk@zjtest7-frontend type]$ cat input.conf input { file { type => "type_a" path => ...

  10. mv command:unable to remove target: Is a director

    mv command:unable to remove target: Is a director This is somewhat simple as long as we understand t ...