• CodeForces 1059B


    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×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 (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.

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

    不知为何,最近总是看错题意,并且非常自信的认为题意就是那样的?

    这个问题需要注意一下了,最近这两场比赛全面崩盘都与看错题意有关,是自己太急躁了吗?

    题中说了,每一笔都需要是一个完成的3*3的矩阵,且样例2也说明了这一点,但我愣是没看出来,导致一直WA。

    很简单,暴力就完事了。

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 #include<math.h>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<stack>
     8 #include<deque>
     9 #include<iostream>
    10 using namespace std;
    11 typedef long long  LL;
    12 
    13 char con[1009][1009];
    14 char note[1009][1009];
    15 int way[]= {1,0,-1,0,0,1,0,-1,1,1,-1,1,-1,-1,1,-1};
    16 
    17 int main()
    18 {
    19     int i,p,j,n,m;
    20     int flag=0;
    21     scanf("%d%d",&n,&m);
    22     for(i=1; i<=n; i++)
    23     {
    24         for(j=1; j<=m; j++)
    25         {
    26             scanf(" %c",&con[i][j]);
    27             if(con[i][j]=='.')
    28             {
    29                 flag++;
    30             }
    31         }
    32     }
    33 
    34     while(1)
    35     {
    36 
    37 //        if(n==3&&m==3&&flag==0)
    38 //        {
    39 //            printf("NO
    ");
    40 //            break;
    41 //        }
    42         for(i=2; i<n; i++)
    43         {
    44             for(j=2; j<m; j++)
    45             {
    46                 for(p=0; p<=15; p+=2)
    47                 {
    48                     int x=i+way[p];
    49                     int y=j+way[p+1];
    50                     if(con[x][y]=='.'&&x>=1&&x<=n&&y>=1&&y<=m)
    51                         break;
    52                 }
    53                 if(p>15)
    54                 {
    55                     for(p=0; p<=15; p+=2)
    56                     {
    57                         int x=i+way[p];
    58                         int y=j+way[p+1];
    59                         if(x>=1&&x<=n&&y>=1&&y<=m)
    60                         {
    61                             note[x][y]='#';
    62                         }
    63                     }
    64                 }
    65             }
    66         }
    67         int check=0;
    68 
    69         for(i=1; i<=n; i++)
    70         {
    71             for(j=1; j<=m; j++)
    72             {
    73                 if(con[i][j]!='.'&&con[i][j]!=note[i][j])
    74                 {
    75                     check=1;
    76                     break;
    77                 }
    78             }
    79             if(check==1)
    80                 break;
    81         }
    82         if(check==1)
    83             printf("NO
    ");
    84         else
    85             printf("YES
    ");
    86         break;
    87     }
    88     return 0;
    89 }
    View Code
  • 相关阅读:
    20200721训练记录
    20200717训练记录
    打家劫舍III(力扣第337题)
    HBase API的删除数据操作的分析
    相交链表(第160题)
    删除排序链表中的重复元素(第83题)
    合并两个有序链表(力扣第21题)
    删除链表的倒数第N个节点(第19题)
    HBase的架构原理
    回文链表、链表求和(234、445)
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9751438.html
Copyright © 2020-2023  润新知