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

#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 ...
随机推荐
- HDU 2669 Romantic( 拓欧水 )
链接:传送门 题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry" 思路:裸 exgcd /***************** ...
- sdoi2013 spring(hash+容斥)
大体思路是先求出来\(f[i]\)代表有至少\(i\)个位置相同的点对数. 然后就已经没什么好害怕的了(跟BZOJ3622一样) 然后这个\(f[i\)]怎么求呢? 最无脑的方法就是枚举位置,然后\( ...
- cmake模板
1.主要命令 project (TEST):指定项目名称为TEST aux_source_directory(<dir> <variable>):将当前目录中的源文件名称赋值给 ...
- el-select 根据value查询其对应的label值
<el-form-item label="库位" prop="goodsLocationId" > <el-col :span="1 ...
- UVALive 5545 Glass Beads
Glass Beads Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Origin ...
- UVALive 3231 Fair Share
Fair Share Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Origina ...
- WINSERVER-IIS-无法启动
报错信息:无法启动计算机上的服务W3SVC 开始百度,多数教程是这样写的 修复错误 运行命令提示符 fsutil resource setautoreset true c:\ 打开运行输入 servi ...
- [Python Test] Use pytest fixtures to reduce duplicated code across unit tests
In this lesson, you will learn how to implement pytest fixtures. Many unit tests have the same resou ...
- [ReactVR] Start a Virtual Reality Project Using the React VR CLI
We will learn how to set up a React VR project, run the development mode with hot reloading, and tak ...
- 从100PV到1亿级PV站点架构演变
假设你对项目管理.系统架构有兴趣,请加微信订阅号"softjg".增加这个PM.架构师的大家庭 一个站点就像一个人,存在一个从小到大的过程. 养一个站点和养一个人一样.不同一时候期 ...