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. SCRUM项目 5.0

    5.0--------------------------------------------------- 1.团队成员完成自己认领的任务. 2.燃尽图:理解.设计并画出本次Sprint的燃尽图的理 ...

  2. (转)注意力机制(Attention Mechanism)在自然语言处理中的应用

    注意力机制(Attention Mechanism)在自然语言处理中的应用 本文转自:http://www.cnblogs.com/robert-dlut/p/5952032.html  近年来,深度 ...

  3. MSSQL 和 REDIS的数据类型对应关系

    when user_type_id in (34) then 'BLOB' --image            when user_type_id in (35) then 'CLOB' --tex ...

  4. Install Slax on USB device (Slax U 盘安装)

    Slax is a modern, portable, small and fast Linux operating system with a modular approach and outsta ...

  5. youtube不显示其他人头像

    我用的是ss , 右键ss选择pac->编辑本地pac 把ggpht.com加入pac列表即可

  6. c#获取枚举

    在实际开发项目中,我们定义了一个枚举,往往我们需要在下拉框或其它地方展示枚举.为了加深印象,也为了帮到有需要的人,我写了一个DEMO. 第一步,我们定义一个枚举: /// <summary> ...

  7. ORA-02049: 超时: 分布式事务处理等待锁的解决方法

    是其他地方执行了操作没有提交,把其他地方提交了就好了

  8. matlab示例程序--Motion-Based Multiple Object Tracking--卡尔曼多目标跟踪程序--解读

    静止背景下的卡尔曼多目标跟踪 最近学习了一下多目标跟踪,看了看MathWorks的关于Motion-Based Multiple Object Tracking的Documention. 官网链接:h ...

  9. jQuery - 疑惑

    设置内容和属性:http://www.runoob.com/jquery/jquery-dom-set.html

  10. 稍览了一下CommonJS

    CommonJS是服务器端模块的规范,现在炒得很火的Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.加载模块使用require方法,该方法读取一个文件并执行,最后 ...