#228(div2)B. Fox and Cross

B. Fox and Cross
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.

A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.

Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.

Please, tell Ciel if she can draw the crosses in the described way.

Input

The first line contains an integer n (3 ≤ n ≤ 100) — the size of the board.

Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.

Output

Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".

Examples
input
5
.#...
####.
.####
...#.
.....
output
YES
input
4
####
####
####
####
output
NO
input
6
.#....
####..
.####.
.#.##.
######
.#..#.
output
YES
input
6
.#..#.
######
.####.
.####.
######
.#..#.
output
NO
input
3
...
...
...
output
YES
题意:问#是否能组成十字架,不可重复利用
思路:模拟
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 char s[103][103];
 5 
 6 int main(){
 7     int n;
 8     cin>>n;
 9     int sum=0;
10     for(int i=1;i<=n;i++){
11         scanf("%s",s[i]+1);
12         for(int j=1;j<=n;j++){
13             if(s[i][j]=='#') sum++;
14         }
15     }
16     if(sum%5!=0) cout<<"NO"<<endl;
17     else {
18         for(int i=1;i<=n;i++){
19             for(int j=1;j<=n;j++){
20                 if(s[i][j]=='#'){
21                     if(s[i+1][j]=='#'&&s[i+2][j]=='#'&&s[i+1][j-1]=='#'&&s[i+1][j+1]=='#'){
22                             s[i][j]='.';
23                         s[i+1][j]='.';s[i+2][j]='.';s[i+1][j-1]='.';s[i+1][j+1]='.';
24                     }
25                     else {
26                         cout<<"NO"<<endl;return 0;
27                     }
28                 }
29             }
30         }
31         cout<<"YES"<<endl;
32     }
33 }

 

posted on 2017-06-30 16:24  hhhhx  阅读(287)  评论(0编辑  收藏  举报

导航