http://poj.org/problem?id=2446

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 18560   Accepted: 5857

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
 
题解:
把棋盘染成这个样子,有障碍的不染,用黑色格子与白色格子匹配,对这一个二分图求最大匹配。如果Ans*2+K=N*M,则能完全覆盖

 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N(*);
int n,m,p,x,y,ans;
int match[N][N][],lose[N][N];
int vis[N][N],sumvis;
int fx[]={,,-,};
int fy[]={,,,-}; bool DFS(int x,int y)
{
for(int i=;i<;i++)
{
int xx=x+fx[i], yy=y+fy[i];
if(vis[xx][yy]!=sumvis&&!lose[xx][yy])
{
vis[xx][yy]=sumvis;
if(!match[xx][yy][]||DFS(match[xx][yy][],match[xx][yy][]))
{
match[xx][yy][]=x;
match[xx][yy][]=y;
return true;
}
}
}
return false;
} int main()
{
while(~scanf("%d%d%d",&n,&m,&p))
{
if((n*m-p)%)
{
printf("NO\n");
continue;
}
ans=sumvis=;
memset(vis,,sizeof(vis));
memset(lose,,sizeof(lose));
memset(match,,sizeof(match));
for(int i=;i<=p;i++)
{
scanf("%d%d",&x,&y);
lose[y][x]=;
}
for(int i=;i<=n;i++)
lose[i][]=lose[i][m+]=;
for(int i=;i<=m;i++)
lose[][i]=lose[n+][i]=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if((i+j)%==&&!lose[i][j])
{
sumvis++;
if(DFS(i,j)) ans++;
}
if(ans*+p==m*n) printf("YES\n");
else printf("NO\n");
}
return ;
}

POJ——T2446 Chessboard的更多相关文章

  1. poj 2446 Chessboard (二分匹配)

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

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

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

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

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

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

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

  5. POJ 2446 Chessboard

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

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

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

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

    题意: M*N的棋盘,规定其中有K个格子不能放任何东西.(即不能被覆盖) 每一张牌的形状都是1*2,问这个棋盘能否被牌完全覆盖(K个格子除外) 思路: M.N很小,把每一个可以覆盖的格子都离散成一个个 ...

  8. POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)

    题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...

  9. POJ 1657 Distance on Chessboard 简单的计算问题

    Distance on Chessboard Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23096   Accepted ...

随机推荐

  1. 论文阅读笔记“Attention-based Audio-Visual Fusion for Rubust Automatic Speech recognition”

    关于论文的阅读笔记 论文的题目是“Attention-based Audio-Visual Fusion for Rubust Automatic Speech recognition”,翻译成中文为 ...

  2. 小学生都能学会的python(函数的进阶)

    小学生都能学会的python(函数的进阶) 1. 动态传参 形参: 1. 位置参数 2. 默认值参数 3. 动态传参 *args 动态接收位置参数 **kwargs 动态接收关键字参数 def fun ...

  3. 小学生都能学会的python(编码 and 字符串)

    小学生都能学会的python(编码 and 字符串) 一,编码 最早的计算机编码是ASCII. 有英文+数字+特殊字符 8bit => 1byte 没有中文, 后面的编码必须兼容ASCII    ...

  4. 单元测试Struts2的Action(包含源码)

    很久没有从头搭建Struts2的环境了.最近,认真实践了单元测试Struts2.Spring等Java项目. 今天特意写的是单元测试Struts2的Action,遇到了不少问题,果然是实践出真知啊. ...

  5. Ubuntu下使用crontab部署定时任务

    Ubuntu下使用crontab部署定时任务 安装cron apt-get install cron 开启crontab日志 默认情况下的日志是没有开启的,我们需要找到 /etc/rsyslog.d/ ...

  6. JS中的NaN

    什么是NaN?它的类型是什么?如何可靠地测试一个值是否等于NaN? NaN属性表示“不是数字”的值.这个特殊值是由于一个操作数是非数字的(例如“abc”/ 4)或者因为操作的结果是非数字而无法执行的. ...

  7. 【codeforces 747E】Comments

    [题目链接]:http://codeforces.com/problemset/problem/747/E [题意] 给你一个类似递归的结构; 让你把每一层的字符串按照层,一层层地输出出来; 并输出层 ...

  8. MyBatis学习总结(5)——实现关联表查询

    一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创建一张教师表和班级表,这里我们假设一个老师只负责教一个班,那么老师和班级之间的关系就是一种一对一的关 ...

  9. GROUP BY 与聚合函数 使用注意点

    表的设计: 表里面的内容: 一:在不使用聚合函数的时候,group by 子句中必须包含所有的列,否则会报错,如下 select name,MON from [测试.] group by name 会 ...

  10. HDU 3240

    求卡特兰数前N项的和模M. 直接求必定是不可能的,卡特兰数太大了.想了好久,本打算把位数拆成素数相乘,然后记录下各素数的个数计算.可惜,TLE....因为N太大了. 除法必定是要用到逆元的,但分母与M ...