Cf # 514b. Forgery (violent)

Source: Internet
Author: User

 

B. Forgery
Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. obviusly, it is impossible to do this by legal means, but Andrey doesn' t give up. having obtained an empty certificate from a local hospate, 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 × 3square 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 ).

Examples
Input
Copy
3 3
###
#.#
###
Output
Copy
Yes
Input
Copy
3 3
###
###
###
Output
Copy
No
Input
Copy
4 3
###
###
###
###
Output
Copy
Yes
Input
Copy
5 7
.......
.#####.
.#.#.#.
.#####.
.......
Output
Copy
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 ):

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

 

Meaning: imitating the instructor's signature. Every write is a 3*3 matrix. There is no ink in the middle. A matrix is provided to indicate the instructor's signature. Ask if the imitation is successful.

Question: brute force. When the input is complete, calculate the number sum of #. The outermost circle is invisible. Starting from the second column in the second row, assume that the position is in the middle of the 3*3 matrix, check whether the circle around this point is always # Or already written #. If it is written once, calculate the number of covered # (not covered before) CNT, and mark the ones that have already been overwritten. Finally, compare whether CNT is equal to sum. If it is equal to sum, it indicates that the simulation is successful.

1 # include <bits/stdc ++. h> 2 using namespace STD; 3 # define ll long 4 char C [1010] [1010]; 5 Int B [8] [2] = {-1, -1}, {-}, {-}, {0,-1}, {}, {1,-1 }, {}}; 6 int main () {7 int n, m, I, j, O; 8 while (CIN> N> m) {9 int sum = 0; 10 for (I = 1; I <= N; I ++) 11 for (j = 1; j <= m; j ++) 12 {13 CIN> C [I] [J]; 14 if (C [I] [J] = '#') sum ++; 15} 16 int CNT = 0; 17 for (I = 2; I <= n-1; I ++) 18 {19 for (j = 2; j <= m-1; j ++) 20 {21 int MD = 0; 22 for (O = 0; O <8; O ++) {// traverse the eight directions around, check whether the image can be painted. 1 indicates that the image has been painted before, but it can still be painted 23 if (C [I + B [O] [0] [J + B [O] [1] = '#' | C [I + B [O] [0] [J + B [O] [1] = '1 ') 24 MD ++; 25 else continue; 26} 27 if (MD = 8) {28 for (O = 0; O <8; O ++) {29 If (C [I + B [O] [0] [J + B [O] [1] = '#') // in order not to count repeatedly, only the # operator can count 30 CNT ++; // indicates the # operator that has been drawn. If the sum is equal to the total # operator, the image can be painted, output Yes 31 C [I + B [O] [0] [J + B [O] [1] = '1 '; 32} 33} 34} 35} 36 IF (CNT = sum) cout <"Yes \ n"; 37 Else cout <"NO \ n "; 38} 39 return 0; 40}

 

Cf # 514b. Forgery (violent)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.