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
 
Source
 

题意:找出十字架个数

思路:列举十字架的中点。dfs时传进去方向,方便推断十字架周围是不是有#(这是不合格的)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector> #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<n&&y>=0&&y<n)
return 1;
return 0;
} void dfs(int x,int y,int i)
{
temp++;
int j;
if(i<2) j=2;
else
j=0; int xx=x+step[i][0];
int yy=y+step[i][1]; if(!judge(xx,yy)) return ; if(a[xx][yy]=='o') return ; int xup=xx+step[j][0];
int ydn=yy+step[j][1]; if(judge(xup,ydn)&&a[xup][ydn]=='#')
{
flag=1;
return ;
}
xup=xx+step[j+1][0];
ydn=yy+step[j+1][1];
if(judge(xup,ydn)&&a[xup][ydn]=='#')
{
flag=1;
return ;
}
dfs(xx,yy,i);
} int main()
{
int i,j;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
scanf("%s",a[i]); ans=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(a[i][j]=='#')
{
temp=0;
flag=0;
dfs(i,j,0);
up=temp;
temp=0;
if(flag) continue;
dfs(i,j,1);
down=temp;
temp=0; if(flag) continue;
dfs(i,j,2);
le=temp;
temp=0; if(flag) continue;
dfs(i,j,3); ri=temp;
temp=0; if(flag) continue; if(le==ri&&down==up&&le!=1&&up!=1) //左右相等。上下相等,不能是一条线
ans++;
} printf("%d\n",ans);
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

最新文章

  1. Win7(x64)升级到Win10
  2. JavaScript 框架设计(二)
  3. REST服务介绍
  4. Python开发程序:学员管理系统(mysql)
  5. react-native 调用 TouchableOpacity (触摸透明) 时报了一个警告
  6. 使用ping钥匙临时开启SSH:22端口,实现远程安全SSH登录管理就这么简单
  7. Android View各种尺寸位置相关的方法探究
  8. mysq 导入 导出
  9. release下去除nslog宏
  10. [Linux] killall 、kill 、pkill 命令详解
  11. 利用firefox调试安卓手机端web
  12. Visual Studio For MacOS .NetCore开发踩坑记
  13. R语言学习——数据框
  14. H5页面长按导致app崩溃问题解决
  15. 常用Linux VPS/服务器SSH连接工具 - Xshell下载与使用
  16. JS的深浅拷贝
  17. ubuntu默认的Python版本号修改
  18. 安卓开发----TextView控件属性列表(转)
  19. nodeJS---URL相关模块用法(url和querystring)
  20. Docker部署Consul集群

热门文章

  1. 删除GitHub上项目中的某个文件
  2. A Guide to Python&#39;s Magic Methods
  3. [ES7] Handle Errors in Asynchronous Functions
  4. [Now] Deploy a Node project with Zeit’s Now
  5. Java并发包探秘 (一) ConcurrentLinkedQueue
  6. js进阶 11-13 jquery如何包裹元素和去除元素外的包裹
  7. Kinect小小玩偶游戏----小小潜水员
  8. SRA解密报错:Data must start with zero
  9. winxp下安装mysql5.7提示mysqld.exe不是有效的win32文件
  10. mysql的四种启动方式