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. 使用剩余参数代替 arguments (prefer-rest-params)

    使用剩余参数代替 arguments (prefer-rest-params) 剩余参数来自于ES2016.可以在可变函数中使用这个特性来替代arguments变量. arguments没有Array ...

  2. redis基本数据类型和对应的底层数据结构

    Redis的数据类型包含string,list,hash,set,sorted set. Redis中定义了一个对象的结构体: /* * Redis 对象 */ typedef struct redi ...

  3. UVALIVE 4256 Salesmen

    Salesmen Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...

  4. 洛谷—— P1260 工程规划

    https://www.luogu.org/problem/show?pid=1260 题目描述 造一幢大楼是一项艰巨的工程,它是由n个子任务构成的,给它们分别编号1,2,…,n(5≤n≤1000). ...

  5. lucene构建restful风格的简单搜索引擎服务

    来自于本人博客: lucene构建restful风格的简单搜索引擎服务 本人的博客如今也要改成使用lucene进行全文检索的功能,因此在这里把代码贴出来与大家分享 一,文件夹结构: 二,配置文件: 总 ...

  6. 为什么选性别会导致兴趣都选中-vue

    为什么选性别会导致兴趣都选中-vue <%@ page language="java" import="java.util.*" pageEncoding ...

  7. bzoj3626【LNOI2014】LCA

    3626: [LNOI2014]LCA Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1266  Solved: 448 [Submit][Stat ...

  8. UESTC 1143 数据传输 网络流 最大流 Dinic

    数据传输 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Sta ...

  9. Test Precisely and Concretely

    Test Precisely and Concretely Kevlin Henney IT IS IMPORTANT TO TEST for the desired, essential behav ...

  10. MonkeyRunner源代码分析之启动

    在工作中由于要追求完毕目标的效率,所以很多其它是强调实战.注重招式.关注怎么去用各种框架来实现目的.可是假设一味仅仅是注重招式.缺少对原理这个内功的了解,相信自己非常难对各种框架有更深入的理解. 从几 ...