码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 1059B

时间:2018-10-07 21:32:41      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:g++   code   技术分享   frame   cal   ade   paper   script   sam   

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\n");
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\n");
84         else
85             printf("YES\n");
86         break;
87     }
88     return 0;
89 }
View Code

 

 

CodeForces 1059B

标签:g++   code   技术分享   frame   cal   ade   paper   script   sam   

原文地址:https://www.cnblogs.com/daybreaking/p/9751438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!