zoukankan      html  css  js  c++  java
  • Codeforces Round #514 (Div. 2) 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.

    1
    2
    3
    xxx
    x.x
    xxx

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

    输入

    The first line of input contains two integers nn and mm (3n,m10003≤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.

    输出

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

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

    样例

    输入

    1
    2
    3
    4
    3 3
    ###
    #.#
    ###

    输出

    YES

    输入

    1
    2
    3
    4
    3 3
    ###
    ###
    ###

    输出

    NO

    输入

    1
    2
    3
    4
    5
    4 3
    ###
    ###
    ###
    ###

    输出

    YES

    输入

    1
    2
    3
    4
    5
    6
    5 7
    .......
    .#####.
    .#.#.#.
    .#####.
    .......

    输出

    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:
    1
    2
    3
    4
    ...
    ...
    ...
    ...
    1. use the pen with center at (2,2)(2,2).
    1
    2
    3
    4
    ###
    #.#
    ###
    ...
    1. use the pen with center at (3,2)(3,2).
    1
    2
    3
    4
    ###
    ###
    ###
    ###

    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).

    思路

    先扫一遍,不必管3x3小格子的中间位置是否空着,只要符合周围8个为’#’便在另一个数组总模拟的“盖章”;

    最后对比一下新旧数组是否一致变好了

    也不知道自己昨晚是怎么回事,傻逼了,div.2第二题都写不出来了。以后cf还是要常打,这种题目要多练练。

    ps:刚发现cf对’YES’跟’Yes’是不加区分的

    下边的代码也能过

    代码

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e3+10;
    int n,m;
    char a[N][N];
    char t[N][N];
    int tx[] = {-1,-1,-1,0,0,1,1,1};
    int ty[] = {-1,0,1,-1,1,-1,0,1};
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
            freopen("in.txt","r",stdin);
        // freopen("out.txt","w",stdout);
    #endif
        scanf("%d %d",&n,&m);
        for(int i = 1;i <= n;i++)   scanf("%s",a[i]+1);
        memset(t,'.',sizeof t);
        for(int i = 2;i < n;i++)
            for(int j = 2;j < m;j++)
            {
                bool flag = 1;
                for(int k = 0;k < 8;k++)
                {
                    if(a[i+tx[k]][j+ty[k]] != '#')
                    {
                        flag = 0;
                        break;
                    }
                }
                if(flag)
                {
                    for(int k = 0;k < 8;k++)
                        t[i+tx[k]][j+ty[k]] = '#';
                }
            }
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= m;j++)
            {
                if(a[i][j] != t[i][j])
                {
                    printf("No
    ");
                    return 0;
                }
            }
        }
        printf("Yes
    ");
        fclose(stdin);
        // fclose(stdout);
        return 0;
    }
    
  • 相关阅读:
    ASCII对应码表-键值(完整版)
    node.js中使用路由方法
    关于vscode自动跳转回车的解决方法(关闭vscode自动保存功能;可能和其他插件有冲突)
    js中 !==和 !=的区别是什么
    spring 请求参数和路径变量
    PowerShell因为在此系统中禁止执行脚本解决方法
    SQL server 2008数据库的备份与还原(亲测,效果良好)注意采用单用户模式呀
    webpack-dev-server提示css模块解析失败,但已经装了css-loader
    webpack集成vue单文件模式的很多坑(研究了1个星期)
    npm全局模块卸载及默认安装目录修改方法
  • 原文地址:https://www.cnblogs.com/duny31030/p/14305133.html
Copyright © 2011-2022 走看看