Tiling Challenge
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:
By the pieces lay a large square wooden board. The board is divided into ?2 cells arranged into ? rows and ? columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free.
Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it’s possible to fully tile the board?
Input
The first line of the input contains a single integer ? (3≤?≤50) — the size of the board.
The following ? lines describe the board. The ?-th line (1≤?≤?) contains a single string of length ?. Its ?-th character (1≤?≤?) is equal to “.” if the cell in the ?-th row and the ?-th column is free; it is equal to “#” if it’s occupied.
You can assume that the board contains at least one free cell.
Output
Output YES if the board can be tiled by Alice’s pieces, or NO otherwise. You can print each letter in any case (upper or lower).
Examples
inputCopy
3
#.#
…
#.#
outputCopy
YES
inputCopy
4
##.#
#…
##.#
outputCopy
NO
inputCopy
5
#.###
…#
#…
###.#
outputCopy
YES
inputCopy
5
#.###
…#
#…
…#
#…##
outputCopy
NO
Note
The following sketches show the example boards and their tilings if such tilings exist:
题目:https://codeforces.com/contest/1150/problem/B
题意判断一幅图上是否有独立的完整类似十字架的点,如果没有,或者十字架上的点有覆盖都输出NO。
首先把整幅图都设成#,遇到. 首先判断它的上下左右是否在这个图里面,其次如果在图里面,且符合条件,则把 . 全变成#(因为防止十字架上的点相互覆盖)。
ps:遇到scanf("%d",&n);n后需要输入字符串的情况,要有getchar(),不然很容易wa掉.
代码如下:
#define rep(i,a,b) for(int i=a;i<=b;++i)
#include < iostream>
#include< cstdio>
#include< algorithm>
#include< cstring>
using namespace std;
const int maxn =55;
int n;
bool flag;
bool mapp[maxn][maxn];
void check(int i,int j){
if(i== 1||i== n||j== 1||j== n){
return ;
}
if(mapp[i][j]&&mapp[i-1][j]&&mapp[i+1][j]&&mapp[i][j-1]&&mapp[i][j+1])
{
mapp[i][j]=mapp[i-1][j]=mapp[i+1][j]=mapp[i][j-1]=mapp[i][j+1]=false;
return ;
}
else
{
return ;
}
}
int main(){
int n;
memset(mapp,false,sizeof(mapp));
scanf("%d",&n);
getchar();//很重要,漏掉会wa
rep(i,1,n)
{
rep(j,1,n){
//char c;
//scanf("%c",&c);
if(getchar()=='.')
mapp[i][j]=true;
}
getchar();
}
rep(i,1,n)
{
rep(j,1,n){
if(mapp[i][j])//只考虑.的情况
check(i,j);
break;
}
}
rep(i,1,n)
rep(j,1,n)
if(mapp[i][j]==true)//排除十字架含有多的点,即只有独立的五个点,但不足以构成新的十字架
{
flag=true;
break;
}
if(flag)
printf("NO\n");
else
printf("YES\n");
return 0;
}