POJ——T2446 Chessboard
http://poj.org/problem?id=2446
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 18560 | Accepted: 5857 |
Description

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
Output
Sample Input
4 3 2
2 1
3 3
Sample Output
YES
Hint
A possible solution for the sample input.
Source
把棋盘染成这个样子,有障碍的不染,用黑色格子与白色格子匹配,对这一个二分图求最大匹配。如果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的更多相关文章
- poj 2446 Chessboard (二分匹配)
Chessboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12800 Accepted: 4000 Descr ...
- POJ 2446 Chessboard (二分图最大匹配)
题目链接:http://poj.org/problem?id=2446 给你一个n*m的棋盘,其中有k个洞,现在有1*2大小的纸片,纸片不能覆盖洞,并且每个格子最多只能被覆盖一次.问你除了洞口之外这个 ...
- poj 2446 Chessboard (二分图利用奇偶性匹配)
Chessboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13176 Accepted: 4118 Descr ...
- POJ 2446 Chessboard (二分图匹配)
题意 在一个N*M的矩形里,用1*2的骨牌去覆盖该矩形,每个骨牌只能覆盖相邻的两个格子,问是否能把每个格子都盖住.PS:有K个孔不用覆盖. 思路 容易发现,棋盘上坐标和为奇数的点只会和坐标和为偶数的点 ...
- POJ 2446 Chessboard
要求用占两格的长方形铺满平面上除去指定点 二分图匹配 #include <iostream> #include <cstdio> #include <cstring> ...
- POJ 2446 Chessboard【二分图最大匹配】
<题目链接> 题目大意: 给你一个n*m的棋盘,其中有k个洞,现在有1*2大小的纸片,纸片不能覆盖洞,并且每个格子最多只能被覆盖一次.问你除了洞口之外这个棋盘是否能被纸片填满. 解题分析: ...
- POJ 2446 Chessboard(二分图最大匹配)
题意: M*N的棋盘,规定其中有K个格子不能放任何东西.(即不能被覆盖) 每一张牌的形状都是1*2,问这个棋盘能否被牌完全覆盖(K个格子除外) 思路: M.N很小,把每一个可以覆盖的格子都离散成一个个 ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- POJ 1657 Distance on Chessboard 简单的计算问题
Distance on Chessboard Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23096 Accepted ...
随机推荐
- BZOJ 5180 [Baltic2016]Cities(斯坦纳树)
斯坦纳树的板子题. 斯坦纳树问题是组合优化问题,与最小生成树相似,是最短网络的一种. 最小生成树是在给定的点集和边中寻求最短网络使所有点连通. 而最小斯坦纳树允许在给定点外增加额外的点,使生成的最短网 ...
- NOIP 2017 时间复杂度 (模拟)
题目大意:略 傻了吧唧的我wa了好几次 我的模拟功底真的不咋地 linux下用gets会报错,我用的fgets #include <string> #include "stdio ...
- PHP下的异步尝试二:初识协程
PHP下的异步尝试系列 如果你还不太了解PHP下的生成器,你可以根据下面目录翻阅 PHP下的异步尝试一:初识生成器 PHP下的异步尝试二:初识协程 PHP下的异步尝试三:协程的PHP版thunkify ...
- vue实现双向绑定原理
- visual studio 2015将已有项目添加到码云(gitee)
visual studio 2015将已有项目添加到码云的步骤包括:gitee新建项目.清空项目及VS发布项目 1.gitee新建项目 2.清空项目 清空项目则会将vs项目的master分支发布到gi ...
- gdb学习-checkpoint,watch
checkpoint的内容参考: http://blog.chinaunix.net/uid-23629988-id-2943273.html 这一篇主要是checkpoint,在next之前加che ...
- 在Visual Studio Code中使用C#以及.net core
Working with C# Using .NET Core in Visual Studio Code Note: VS Code does not support debugging appli ...
- Xshell dns tunnel攻击
该域名还会向多个超长域名做渗出,且域名采用了 DGA 生成算法,通过 DNS 解析时渗出数据. 部分生成域名如下: sajajlyoogrmkjlkmosbxowcrmwlvajdkbtbjoylyp ...
- nyoj--301--递推求值(经典矩阵运算)
递推求值 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 给你一个递推公式: f(x)=a*f(x-2)+b*f(x-1)+c 并给你f(1),f(2)的值,请求出f(n ...
- Linux就该这么学 20181005(第七章磁盘管理)
参考链接https://www.linuxprobe.com lsblk检测硬盘使用情况 RAID 技术把多块物理硬盘设备(至少两块)通过硬件或软件的方式串联在一起,组成一个大的卷组,并将数据依次写入 ...