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 (3≤n,m≤10003≤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
3 3
###
#.#
###
YES
3 3
###
###
###
NO
4 3
###
###
###
###
YES
5 7
.......
.#####.
.#.#.#.
.#####.
.......
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):
- we have a clear paper:
...
...
...
... - use the pen with center at (2,2)(2,2).
###
#.#
###
... - 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 }