#228(div2)B. Fox and Cross
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.
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 a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
5
.#...
####.
.####
...#.
.....
YES
4
####
####
####
####
NO
6
.#....
####..
.####.
.#.##.
######
.#..#.
YES
6
.#..#.
######
.####.
.####.
######
.#..#.
NO
3
...
...
...
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 }