Above is the description of Nazca Lines from Wikipedia. Recently scientists found out that those lines form many crosses. Do those crosses have something to do with the Christian religion? Scientists are curious about this. But at first, they want to figure out how many crosses are there. So they took a huge picture of Nazca area from the satellite, and they need you to write a program to count the crosses in the picture.
To simplify the problem, we assume that the picture is an N*N matrix made up of 'o' and '#', and some '#' can form a cross. Here we call three or more consecutive '#' (horizontal or vertical) as a "segment".
The definition of a cross of width M is like this:
1) It's made up of a horizontal segment of length M and a vertical segment of length M.
2) The horizontal segment and the vertical segment overlap at their centers.
3) A cross must not have any adjacent '#'.
4) A cross's width is definitely odd and at least 3, so the above mentioned "centers" can't be ambiguous.
For example, there is a cross of width 3 in figure 1 and there are no cross in figure 2 ,3 and 4.
You may think you find a crZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3MgaW4gdGhlIHRvcCAzIGxpbmVzIGluIGZpZ3VyZSAyLkJ1dCBpdA=="s not true because the cross you find has a adjacent '#' in the 4th line, so it can't be called a "cross". There is no cross in figure 3 and figure 4 because of the same reason.
Input There are several test cases.
In each test case:
The First line is a integer N, meaning that the picture is a N * N matrix ( 3<=N<=50) .
Next N line is the matrix.
The input end with N = 0
Output For each test case, output the number of crosses you find in a line.
Sample Input
4 oo#o o### oo#o ooo# 4 oo#o o### oo#o oo#o 5 oo#oo oo#oo ##### oo#oo oo##o 6 ooo#oo ooo##o o##### ooo#oo ooo#oo oooooo 0
Sample Output
1 0 0 0
Source 2012 ACM/ICPC Asia Regional Hangzhou Online
题意:找出十字架个数
思路:列举十字架的中点,dfs时传进去方向,方便判断十字架周围是不是有#(这是不合格的)
#include#include #include #include #include #include #include #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) using namespace std; #define N 55 int ans,le,ri,up,down,temp; int n,flag; int step[4][2]={-1,0,1,0,0,-1,0,1};//上,下,左,右 char a[N][N]; int judge(int x,int y) { if(x>=0&&x =0&&y