Problem Description
The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in southern Peru. They were designated as a UNESCO World Heritage Site in 1994. The high, arid plateau stretches more than 80 kilometres (50 mi) between the towns of Nazca and Palpa on the Pampas de Jumana about 400 km south of Lima. Although some local geoglyphs resemble Paracas motifs, scholars believe the Nazca Lines were created by the Nazca culture between 400 and 650 AD.[1] The hundreds of individual figures range in complexity from simple lines to stylized hummingbirds, spiders, monkeys, fish, sharks, orcas, llamas, and lizards.

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 cross in the top 3 lines in figure 2.But it'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
#include<stdio.h>
int n,sk,hk,s,h,stakH[1000],stakS[1000],right,lift,up,dow,zxloct;
char map[105][105];
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; void DFS(int i,int j)
{
int e;
map[i][j]='o';
if(stakS[s]==j)
dow++;
for(e=0;e<4;e++)
if(e<2)
{
if(i+dir[e][0]>=0&&i+dir[e][0]<n&&j>=0&&j<n)
if(map[i+dir[e][0]][j]=='#')
{
sk++;
if(j!=stakS[s])
stakS[++s]=j;
DFS(i+dir[e][0],j+dir[e][1]);
}
}
else
{
if(i>=0&&i<n&&j+dir[e][1]>=0&&j+dir[e][1]<n)
if(map[i][j+dir[e][1]]=='#')
{
hk++;
if(e==2)
right++;
else
lift++;
if(i!=stakH[h])
stakH[++h]=i;
if(zxloct==-1)
{
zxloct=i; dow--;
} DFS(i,j+dir[e][1]);
}
}
if(zxloct==-1)
{
dow--;up++;
}
}
int main()
{
int i,j,k;
while(scanf("%d",&n)==1&&n)
{
k=0;getchar();
for(i=0;i<n;i++)
{
scanf("%s",map[i]);
getchar();
}
stakH[0]=-1;
stakS[0]=-1;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(map[i][j]=='#')
{
hk=s=h=0;
right=lift=0;
up=dow=0;
zxloct=-1;
sk=1;stakS[++s]=j;
DFS(i,j);
if(s==1&&h==1&&sk%2==1&&hk%2==0&&hk>0&&sk>1&&right==lift&&up==dow&&lift!=0&&up!=0)
k++;
} printf("%d\n",k);
}
}

hdu4414(DFS 找十字架数量)的更多相关文章

  1. CodeForces - 103B(思维+dfs找环)

    题意 https://vjudge.net/problem/CodeForces-103B 很久很久以前的一天,一位美男子来到海边,海上狂风大作.美男子希望在海中找到美人鱼 ,但是很不幸他只找到了章鱼 ...

  2. # 「银联初赛第一场」自学图论的码队弟弟(dfs找环+巧解n个二元一次方程)

    「银联初赛第一场」自学图论的码队弟弟(dfs找环+巧解n个二元一次方程) 题链 题意:n条边n个节点的连通图,边权为两个节点的权值之和,没有「自环」或「重边」,给出的图中有且只有一个包括奇数个结点的环 ...

  3. CodeForces 711D Directed Roads (DFS找环+组合数)

    <题目链接> 题目大意: 给定一个$n$条边,$n$个点的图,每个点只有一条出边(初始状态),现在能够任意对图上的边进行翻转,问你能够使得该有向图不出先环的方案数有多少种. 解题分析: 很 ...

  4. dfs找負環

    某些無良出題人可能會卡bfs找負環,所以要用dfs 核心代碼(以jzoj5173為例): #include<bits/stdc++.h> using namespace std; #def ...

  5. leetcode-200-岛屿的个数(dfs找所有的连通分量)

    题目描述: 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量.一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的.你可以假设网格的四个边均被水包围. 示例 ...

  6. Codeforces Beta Round #87 (Div. 2 Only)-Party(DFS找树的深度)

    A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exa ...

  7. HDU 4665 Unshuffle DFS找一个可行解

    每层找一对相等的整数,分别放在两个不同的串中. 参考了学弟的解法,果断觉得自己老了…… #include <cstdio> #include <cstring> #includ ...

  8. Codeforces Round #369 (Div. 2) D. Directed Roads —— DFS找环 + 快速幂

    题目链接:http://codeforces.com/problemset/problem/711/D D. Directed Roads time limit per test 2 seconds ...

  9. HDU 1242 dFS 找目标最短路

    //多个起点,要最短得目标,不妨倒过来从目标出发,去找最近的点更新!!!!!!递归时思路要清楚 #include<iostream> #include<cstring> usi ...

随机推荐

  1. jquery动态刷新局部表单

    想实现一个效果就是选择某个年份:然后再action中按该年份查找数据库中的数据,返回到页面表单中显示. 1.添加登记年度的changge事件,也是异步请求. $(document).ready(fun ...

  2. Java生成CSV文件

    1.新CSVUtils.java文件: package com.saicfc.pmpf.internal.manage.utils; import java.io.BufferedWriter; im ...

  3. MongoDB在window下的安装

    1.下载mongodb的windows版本号,有32位和64位版本号,依据系统情况下载,下载地址:http://www.mongodb.org/downloads 2.解压缩至D:/mongodb就可 ...

  4. SSAS系列——【02】多维数据(维度对象)

    原文:SSAS系列——[02]多维数据(维度对象) 1.维度是什么? 数学中叫参数,物理学中是独立的时空坐标的数目.0维是一点,1维是线,2维是一个长和宽(或曲线)面积,3维是2维加上高度形成体积面. ...

  5. 有趣Web之Json(四)---json与(Object/List/Map)相互转化

    干web报名时间.通常,他们需要json转换为Object/list/map要么Object/List/map转换为json,由能够编写代码的简单包装非常多,以减轻负担. 本文将给出json的一系列的 ...

  6. MVC验证02-自定义验证规则、邮件验证

    原文:MVC验证02-自定义验证规则.邮件验证 本文体验MVC自定义验证特性,来实现对邮件的验证.对于刚写完的自定义验证特性,起初只能支持后端验证.如果要让前端jquery支持,还必须对jquery的 ...

  7. IOS被遗忘的知识

    IOS ARC项目使用非ARC文件 1.自己的旧项目没有使用ARC,可是引入的第三方库却是使用了ARC的. 对于第一个情况,给採用了ARC的源文件,加入-fobjc-arc选项 2.自己的新项目使用了 ...

  8. Zend server最大化应用程序的性能、扩展性和可用性

    如果我有8个小时去砍到一棵树,我会花6个小时磨斧子”——林肯(美国总统) 你可以知道? 世界页面访问量的峰值超过7000万每分钟. CloudFare公司服务器问题,导致785000站点崩溃一小时. ...

  9. Plugin For KanColleViewer – Provissy Tools V1.0

    これはKanColleViewerためのプラグインです,KanColleViewerの機能を拡張する. #介绍 / Introduction / 紹介这是一个KanColleViewer(俗称”提督很 ...

  10. sql内置函数pivot强大的行转列功能

    原文:sql内置函数pivot强大的行转列功能 语法: PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVO ...