Chessboard
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 14787   Accepted: 4607

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
 
 
题目意思:
一个n*m的棋盘,现用1*2的木板覆盖棋盘,其中有黑色圆的棋盘单位不能被覆盖。问能否把棋盘中可以覆盖的单位全部覆盖(不能重复覆盖)。
 
思路:
相邻棋盘单位奇偶性不同建图,判断最大匹配*2是否等于可以覆盖点数即可。
 
 
代码:
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 35 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n, m;
vector<int>ve[N*N];
int from[N*N];
bool visited[N*N]; int march(int u){
int i, v;
for(i=;i<ve[u].size();i++){
v=ve[u][i];
if(!visited[v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
}
int map[N][N];
main()
{
int i, j, k; int x, y;
while(scanf("%d %d %d",&n,&m,&k)==){
memset(map,-,sizeof(map));
int maxh=;
for(i=;i<n;i++){
for(j=;j<m;j++){
if(j==){
if(i==) map[i][j]=;
else {
if(m&) map[i][j]=map[i-][m-]+;
else map[i][j]=map[i-][m-]+;
}
}
else map[i][j]=map[i][j-]+;
maxh=max(maxh,map[i][j]);
// printf("%d ",map[i][j]);
}
//cout<<endl;
}
for(i=;i<k;i++){
scanf("%d %d",&x,&y);
map[y-][x-]=-;
}
int nn=;
for(i=;i<n;i++){
for(j=;j<m;j++){
if(map[i][j]==-) nn++;
}
} for(i=;i<=maxh;i++) ve[i].clear();
for(i=;i<n;i++){
for(j=;j<m;j++){
if(map[i][j]!=-&&(map[i][j]&)){
if(i>&&map[i-][j]!=-) ve[map[i][j]].push_back(map[i-][j]);
if(i<n-&&map[i+][j]!=-) ve[map[i][j]].push_back(map[i+][j]);
if(j>&&map[i][j-]!=-) ve[map[i][j]].push_back(map[i][j-]);
if(j<m-&&map[i][j+]!=-) ve[map[i][j]].push_back(map[i][j+]);
}
}
}
int num=;
memset(from,-,sizeof(from));
for(i=;i<=maxh;i++){
memset(visited,false,sizeof(visited));
if((i&)&&march(i)) num++;
}
if(num*==n*m-nn) printf("YES\n");
else printf("NO\n");
}
}

POJ 2446 最小点覆盖的更多相关文章

  1. POJ 2226 最小点覆盖(经典建图)

    Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8881   Accepted: 3300 Desc ...

  2. poj 3041 最小点覆盖=最大匹配

    #include<stdio.h> #include<string.h> #define  N  510 int map[N][N],n,mark[N],link[N]; in ...

  3. Poj(1325),最小点覆盖

    题目链接:http://poj.org/problem?id=1325 Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total ...

  4. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  5. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  6. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. POJ 3041 Asteroids (二分图最小点覆盖)

    题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...

  8. [POJ] 2226 Muddy Fields(二分图最小点覆盖)

    题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...

  9. 二分图 最小点覆盖 poj 3041

    题目链接:Asteroids - POJ 3041 - Virtual Judge  https://vjudge.net/problem/POJ-3041 第一行输入一个n和一个m表示在n*n的网格 ...

随机推荐

  1. Together

  2. C#的path.GetFullPath 获取上级目录实现方法

    这篇文章主要介绍了C#的path.GetFullPath 获取上级目录实现方法,包含了具体的C#实现方法以及ASP.net与ASP等的方法对比,非常具有实用价值,需要的朋友可以参考下   本文实例讲述 ...

  3. 批处理命令——for

    [1]for命令简介 先把for循环与for命令类比一下,这样学习理解快. for 循环语句,一般格式如下: for (表达式1;表达式2;表达式3) { 循环体; } 1. 表达式1 一般为初始状态 ...

  4. Maven打包pom里面配置exclude 排除掉环境相关的配置文件

    Maven打包pom里面配置exclude 排除掉环境相关的配置文件 有几种方式:1. 打包时,指定环境参数把环境的配置文件复制过去2. 不打包所有的环境相关的配置文件,直接由运维的人维护 可以在上传 ...

  5. jquery之empty()与remove()区别

    要用到移除指定元素的时候,发现empty()与remove([expr])都可以用来实现.可仔细观察效果的话就可以发现.empty()是只移除了 指定元素中的所有子节点,拿$("p" ...

  6. Dynamics AX 2012 R2 在AIF服务契约中使用DateTime

    Reinhard在AIF中使用DateTime作为服务契约的参数,与DotNet程序进行交互时,总是因为时区的问题,导致DotNet提交的System.DateTime与AIF中接收的DateTime ...

  7. windows 8.1无人值守安装

    上个星期网上泄漏了微软最新的操作系统Windows 8.1,我便迫不及待的下载下来进行体验.发现其安装过程交互次数太多,太过漫长,遂研究了一下无人值守安装,现将成果记录如下. 一. 微软有专门的布署工 ...

  8. Java 基础知识 练习题

    利用文本编辑器输入课堂上练习的Hello.java,并在JDK环境下编译和运行.请将程序编译.运行的结果截图.

  9. HTML5正确的嵌入flash

    <object type="application/x-shockwave-flash" data="your-flash-file.swf" width ...

  10. 【SSO单点系列】(3):CAS4.0 登录页验证码的添加

    2016.08.23 更新 注意:这个教程只适合4.0版本的,4.1以及以上的版本的已经不试用了, 后面几篇有人提到过 源码网盘链接更新了下 : 链接: http://pan.baidu.com/s/ ...