![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
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.
![](https://i-blog.csdnimg.cn/blog_migrate/d96f79ce96ef812e23696b1971e9bb84.png)
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
In example 1, you can draw two crosses. The picture below shows what they look like.
![](https://i-blog.csdnimg.cn/blog_migrate/326d77a6ce559c988d9ab061afa41021.png)
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
题型:贪心
题意:在由‘#’和‘.’构成的n*n的地图中,问所有的‘#’能否不重叠的构成多个十字,如果全是‘.’也输出YES
分析:
直接贪心遍历,如果当前的一个点是‘#‘并且其上下左右也是’#’,那么就将这五个点全部改成‘#’,最后再将地图遍历一遍,如果还存在‘#’,则输出NO。
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
char map[123][123];
bool isin(int x,int y) {
if(x>=0 && x<n && y>=0 && y<n) return true;
else return false;
}
bool check(int x,int y) {
if(isin(x-1,y) && isin(x+1,y) && isin(x,y+1) && isin(x,y-1)) {
if(map[x-1][y]=='#' && map[x+1][y]=='#' && map[x][y+1]=='#' && map[x][y-1]=='#')
return true;
}
return false;
}
void change(int x,int y){
map[x][y] = '.';
}
int main() {
while(~scanf("%d",&n)) {
for(int i=0; i<n; i++) {
scanf("%s",map[i]);
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(map[i][j]=='#' && check(i,j))
{
change(i,j);
change(i-1,j);
change(i+1,j);
change(i,j-1);
change(i,j+1);
}
}
}
bool flag = true;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(map[i][j] == '#'){
flag = false;
break;
}
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}