Layout(拆分约束系统 => 最短路)

                                                                      B. Forgery

Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3 square without its central cell if it is completely contained inside the grid, as shown below.

xxx
x.x
xxx

Determine whether is it possible to forge the signature on an empty n×mn×m grid.

Input

The first line of input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000 ).

Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

Output

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).

Examples

Input

Copy

3 3
###
#.#
###

Output

Copy

YES

Input

Copy

3 3
###
###
###

Output

Copy

NO

Input

Copy

4 3
###
###
###
###

Output

Copy

YES

Input

Copy

5 7
.......
.#####.
.#.#.#.
.#####.
.......

Output

Copy

YES

Note

In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2) .

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2) :

  1. we have a clear paper:
    ...
    ...
    ...
    ...
    
  2. use the pen with center at (2,2)(2,2) .
    ###
    #.#
    ###
    ...
    
  3. use the pen with center at (3,2)(3,2) .
    ###
    ###
    ###
    ###
    

In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5) .

 

题意:男孩子Andrey没写一个字都是形如:

           ###

           #.#

           ###

          问他是否能够模仿输入的笔记,如果能输出  YES, 否则输出 NO

思路:遍历每一个点,每次以该点为中心,判断是以该点为中心时,是否能够画出既定的图形(在判断时最好用枚举的办法取判断每一个点,不易出错),如果能画出,在另一张空白的纸上在画一遍,最终看两幅画是否相同,如果相同,输出YES, 不相同输出 NO。

 

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>

using namespace std;

const int maxn = 1e3+5;

char maze[maxn][maxn];
char zhi[maxn][maxn];

int n, m;

//判断是否正确 
bool judge(int x, int y){
	if(maze[x-1][y-1] == '#'&&maze[x][y-1] == '#'&&maze[x+1][y-1] == '#'
	&&maze[x-1][y] == '#'&&maze[x+1][y] == '#'
	&&maze[x-1][y+1] == '#'&&maze[x][y+1] == '#'&&maze[x+1][y+1] == '#')
		return true;
	
	else return false;
}

//在另一张纸上画出 
void Update(int x, int y){
	zhi[x-1][y-1] = '#'; zhi[x][y-1] = '#'; zhi[x+1][y-1] = '#';
	zhi[x-1][y] = '#'; zhi[x+1][y] = '#';
	zhi[x-1][y+1] = '#'; zhi[x][y+1] = '#'; zhi[x+1][y+1] = '#';	 
}

int main()
{
	scanf("%d%d", &n, &m);
	memset(zhi, '.', sizeof(zhi));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++) scanf(" %c", &maze[i][j]);
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(judge(i, j)) Update(i, j);
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(zhi[i][j] == maze[i][j]) continue;
			else{
				printf("NO\n");
				return 0; 
			}
		}
	}
	
	printf("YES\n");
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值