Forgery(CodeForces 1059B)

探讨一种特殊算法,用于判断是否能通过特定方式伪造医生签名,分析了算法的实现过程及核心逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

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×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×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≤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).

Sample Input

Input

3 3
###
#.#
###

Output

YES

Input

3 3
###
###
###

Output

NO

Input

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

Output

YES

Input

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

Output

YES

Hint

In the first sample Andrey can paint the border of the square with the center in (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)and (3,2):

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

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

题解:根据已知方阵构造一个满足条件的方阵,对比差别。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;


char a[1111][1111],b[1111][1111];
int main()
{
    memset(a,'.');
    memset(b,'.');
    int n,m;
    cin>>n>>m;
    int l,r;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
        }
    for(int i=0; i<n-2; i++)
        for(int j=0; j<m-2; j++)
        {
            if(a[i][j]=='#'&&a[i][j+1]=='#'&&a[i][j+2]=='#'&&a[i+1][j]=='#'&&a[i+2][j]=='#'&&a[i+1][j+2]=='#'&&a[i+2][j+1]=='#'&&a[i+2][j+2]=='#')
                b[i][j]='#',b[i][j+1]='#',b[i][j+2]='#',b[i+1][j]='#',b[i+2][j]='#',b[i+1][j+2]='#',b[i+2][j+1]='#',b[i+2][j+2]='#';
        }
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(a[i][j]!=b[i][j])
            {
                //cout<<i<<j<<endl;
                cout<<"NO"<<endl;
                return 0;
            }
    cout<<"YES"<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值