Chessboard
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 12800   Accepted: 4000

Description

Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below). 

We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below: 
1. Any normal grid should be covered with exactly one card. 
2. One card should cover exactly 2 normal adjacent grids.

Some examples are given in the figures below: 
 
A VALID solution.
 
An invalid solution, because the hole of red color is covered with a card.
 
An invalid solution, because there exists a grid, which is not covered.
Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.

Input

There are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.

Output

If the board can be covered, output "YES". Otherwise, output "NO".

Sample Input

4 3 2
2 1
3 3

Sample Output

YES

Hint

 
A possible solution for the sample input.

Source

POJ Monthly,charlescpp

和 hdu 1507类似,构无向图然后判断匹配数是否等于合法的格数。

心算32*32错了= = RE了两次,开始以为32*32是90+,第二次以为是900+,笔算后才知道是1024..

 //224K    125MS    C++    1731B    2014-06-10 12:44:41
#include<iostream>
#include<vector>
#define N 1050
using namespace std;
vector<int>V[N];
int match[N];
int vis[N];
int g[][];
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary(int n)
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int n,m,k,x,y;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(g,,sizeof(g));
for(int i=;i<N;i++) V[i].clear();
for(int i=;i<k;i++){
scanf("%d%d",&y,&x);
g[x-][y]=;
}
int map[N]={},pos=;
for(int i=;i<n;i++)
for(int j=;j<=m;j++)
if(!g[i][j]){
if(!map[i*m+j]) map[i*m+j]=++pos;
int u=map[i*m+j];
if(j<m && !g[i][j+]){
if(!map[i*m+j+]) map[i*m+j+]=++pos;
V[u].push_back(map[i*m+j+]);
V[map[i*m+j+]].push_back(u);
}
if(i<n- && !g[i+][j]){
if(!map[(i+)*m+j]) map[(i+)*m+j]=++pos;
V[u].push_back(map[(i+)*m+j]);
V[map[(i+)*m+j]].push_back(u);
}
}
//printf("%d\n",pos);
if(hungary(pos)==pos) puts("YES");
else puts("NO");
}
return ;
}

poj 2446 Chessboard (二分匹配)的更多相关文章

  1. POJ 2446 Chessboard (二分图匹配)

    题意 在一个N*M的矩形里,用1*2的骨牌去覆盖该矩形,每个骨牌只能覆盖相邻的两个格子,问是否能把每个格子都盖住.PS:有K个孔不用覆盖. 思路 容易发现,棋盘上坐标和为奇数的点只会和坐标和为偶数的点 ...

  2. poj 2446 Chessboard (二分图利用奇偶性匹配)

    Chessboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13176   Accepted: 4118 Descr ...

  3. POJ 3041 - 最大二分匹配

    这道题实现起来还是比较简单的,但是理解起来可能有点困难. 我最开始想到的是贪心法,每次消灭当前小行星最多的一行或一列.然而WA了.Discuss区里已经有高人给出反例. 下面给出正确的解法 我们把行和 ...

  4. POJ 2446 Chessboard (二分图最大匹配)

    题目链接:http://poj.org/problem?id=2446 给你一个n*m的棋盘,其中有k个洞,现在有1*2大小的纸片,纸片不能覆盖洞,并且每个格子最多只能被覆盖一次.问你除了洞口之外这个 ...

  5. POJ 2446 Chessboard

    要求用占两格的长方形铺满平面上除去指定点 二分图匹配 #include <iostream> #include <cstdio> #include <cstring> ...

  6. POJ 2446 Chessboard【二分图最大匹配】

    <题目链接> 题目大意: 给你一个n*m的棋盘,其中有k个洞,现在有1*2大小的纸片,纸片不能覆盖洞,并且每个格子最多只能被覆盖一次.问你除了洞口之外这个棋盘是否能被纸片填满. 解题分析: ...

  7. POJ 3057 Evacuation (二分匹配)

    题意:给定一个图,然后有几个门,每个人要出去,但是每个门每个秒只能出去一个,然后问你最少时间才能全部出去. 析:初一看,应该是像搜索,但是怎么保证每个人出去的时候都不冲突呢,毕竟每个门每次只能出一个人 ...

  8. POJ 2289 多重二分匹配+二分 模板

    题意:在通讯录中有N个人,每个人能可能属于多个group,现要将这些人分组m组,设各组中的最大人数为max,求出该最小的最大值 下面用的是朴素的查找,核心代码find_path复杂度是VE的,不过据说 ...

  9. POJ 1469 ZOJ1140 二分匹配裸题

    很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...

随机推荐

  1. vim 学习日志(4):多窗口使用技巧

    原文地址: http://blog.csdn.net/devil_2009/article/details/7006113 vim多窗口使用技巧 1.打开多个窗口打开多个窗口的命令以下几个:横向切割窗 ...

  2. git 服务器的搭建

    文章转载地址:http://www.linuxidc.com/Linux/2015-05/117502.htm 亲测可行,已经自己搭建一个正在使用中,搭建完成后,结合着pycharm +git,就能直 ...

  3. Bootstrap for MVC:Html.Bootstrap().TextBoxFor(model=>model.Name)

    在上篇博文中提到最近比较忙,也打过招呼Orchard系列文章更新速度可能会放缓,但还是会继续写下去,主要原因在最近想着开发一个新的东西(系统?组件?),等有一定成果时会跟大家分享一些相关的东西,今天介 ...

  4. spring component-scan filter

    (参考的Spring version : 4.1.6.RELEASE) 我们通常会使用component-scan来进行bean的加载,但是它里面的实现机制却是一知半解.根据原码来理解一下,可能会更加 ...

  5. [IIS]IIS扫盲(二)

    iis - IIS之Web服务器建立 第一篇 IIS之Web服务器  一.建立第一个Web站点  比如本机的IP地址为192.168.0.1,自己的网页放在D:\Wy目录下,网页的首页文件名为Inde ...

  6. HTC ONE里面一个非常奇怪的问题。。。调用kSOAP出错

    也是在某统计网站上看到了我们的APP爆出了这么一个bug: java.lang.NoSuchFieldError: No instance field headerOut of type [Lorg/ ...

  7. BVT & BAT & SVT

    1. BVT(Build Verification Test) a. BVT概念 Build Verification test is a set of tests run on every new ...

  8. Centos中的Docker 配置:将loop-lvm改为derict-lvm

    重新装了个虚拟机,回顾一下最近三天的工作: Centos 查看版本 cat /etc/redhat-release yum -y upgrade 升级所有包,不改变软件设置和系统设置,系统版本升级,内 ...

  9. python 版本问题大全

    坑一 一下午的时间又让这个不是问题的问题给白白给浪费了,此片文章仅仅纪念一下浪费掉的宝贵时间 新式类与经典类问题 class qwe: def __init__(self, name): self.n ...

  10. 使用Freemarker宏进行可扩展式模块化编程

    作者:Chu Lung 原文链接:http://blog.chulung.com/article/13 本文由MetaCLBlog于2016-07-08 14:42:10自动同步至cnblogs 一. ...