Codeforces Round #556 (Div. 2)B - Tiling Challenge

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值