Codeforces1059B.Forgery题解

B. Forgery

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

【Problem】

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.

http://codeforces.com/contest/1059/problem/B

【题解】

从上到下,从左到右地遍历。
若当前点为‘#’字符,则将它作为这个3*3矩阵的左上角覆盖,即可完成本问题。

【AC代码】

#include<cstdio>
#include<iostream>
int n,m,p[1005][1005];
char a[1005][1005];
void BFS(int x,int y)
{
    if(x+1>n||y+1>m||x+2>n||y+2>m)  return;
    if(a[x][y]=='.'||a[x+1][y]=='.'||a[x+2][y]=='.'||a[x][y+1]=='.'||a[x][y+2]=='.'||a[x+1][y+2]=='.'||a[x+2][y+1]=='.'||a[x+2][y+2]=='.') return;
    p[x][y]=p[x+1][y]=p[x+2][y]=p[x][y+1]=p[x][y+2]=p[x+1][y+2]=p[x+2][y+1]=p[x+2][y+2]=true;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=n;++i)
        for(register int j=1;j<=m;++j)
            std::cin>>a[i][j];
    for(register int i=1;i<=n;++i)
        for(register int j=1;j<=m;++j)
          if(a[i][j]=='#') BFS(i,j);
    for(register int i=1;i<=n;++i)
        for(register int j=1;j<=m;++j)
          if(a[i][j]=='#'&&!p[i][j])
            {
                puts("NO");
                return 0;
            }
    puts("YES");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值