Finding crosses

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1631 Accepted Submission(s): 868

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

代码

  1. const int maxn=55;
  2. char map[maxn][maxn];
  3. int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
  4. int n;
  5. bool ok(int x,int y){
  6. return x>=0&&x<n&&y>=0&&y<n;
  7. }
  8. bool check(int x,int y){
  9. int cnt=0;
  10. for(int i=1;i<=25;i++){
  11. int tmpc=0;
  12. for(int j=0;j<4;j++){
  13. int xx=x+dx[j]*i,yy=y+dy[j]*i;
  14. if(ok(xx,yy) && map[xx][yy]=='#'){
  15. tmpc++;
  16. if(j%2==0){
  17. if(yy>0&&map[xx][yy-1]=='#' || yy<n-1&&map[xx][yy+1]=='#')return false;
  18. cnt++;
  19. }
  20. else {
  21. if(xx>0&&map[xx-1][yy]=='#' || xx<n-1&&map[xx+1][yy]=='#')return false;
  22. cnt++;
  23. }
  24. }
  25. }
  26. if(tmpc==0)break;
  27. if(tmpc!=4)return false;
  28. }
  29. if(cnt%2==0&&cnt>0)return true;
  30. else return false;
  31. }
  32. int main(){
  33. while(scanf("%d",&n)&&n){
  34. for(int i=0;i<n;i++){
  35. for(int j=0;j<n;j++)scanf(" %c",&map[i][j]);
  36. }
  37. int ans=0;
  38. for(int i=0;i<n;i++){
  39. for(int j=0;j<n;j++){
  40. if(map[i][j]=='#' && check(i,j))ans++;
  41. }
  42. }
  43. printf("%d\n",ans);
  44. }
  45. }

HDOJ 4414 Finding crosses 暴力!的更多相关文章

  1. hdu 4414 Finding crosses【简单模拟】

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414 CSUST:点击打开链接 Finding crosses Time Limit: 2000/1000 ...

  2. hdu 4414 Finding crosses

    题目链接:hdu 4414 其实是一道简单的字符型水题,不涉及任何算法,可比赛时却没能做出来,这几天的状态都差到家了... 题目大意是求有多少个满足条件的十字架,十字架的边不能有分叉路口,所以枚举每个 ...

  3. HDU 4414 Finding crosses(dfs)

    Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...

  4. HDU 4414 Finding crosses (DFS + BFS)

    题意:在N*N的图中,找出孤立存在的十字架的个数.十字架要求为正十字,孤立表示组成十字架的‘#的周围的一格再无’#‘. dfs找出在中心的‘#’(周围四格也为‘#'),则缩小了搜索范围,再bfs找出是 ...

  5. HDU-4414 Finding crosses 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4414 直接暴力判断即可. //STATUS:C++_AC_15MS_232KB #include &l ...

  6. HDOJ 1334 Perfect Cubes(暴力)

    Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > ...

  7. [GodLove]Wine93 Tarining Round #7

    比赛链接: http://vjudge.net/contest/view.action?cid=47643#overview 比赛来源: 2012 ACM/ICPC Asia Regional Han ...

  8. 暴力/思维 HDOJ 5386 Cover

    题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...

  9. 状态压缩 + 暴力 HDOJ 4770 Lights Against Dudely

    题目传送门 题意:有n*m的房间,'.'表示可以被点亮,'#'表示不能被点亮,每点亮一个房间会使旁边的房间也点亮,有意盏特别的灯可以选择周围不同方向的房间点亮.问最少需要多少灯使得所有房间点亮 分析: ...

随机推荐

  1. Linux的bg和fg命令 ---让程序在前台后台之间切换

    Linux的bg和fg命令 我们都知道,在 Windows 上面,我们要么让一个程序作为服务在后台一直运行,要么停止这个服务.而不能让程序在前台后台之间切换.而 Linux 提供了 fg 和 bg 命 ...

  2. spark技术总结(1)

    1. 请描述spark RDD原理与特征 RDD为Resilient Distributed Datasets缩写,译文弹性分布式数据集. 他是spark系统中的核心数据模型之一,另外一个是DAG模型 ...

  3. drop out为什么能够防止过拟合

    来源知乎: dropout 的过程好像很奇怪,为什么说它可以解决过拟合呢?(正则化) 取平均的作用: 先回到正常的模型(没有dropout),我们用相同的训练数据去训练5个不同的神经网络,一般会得到5 ...

  4. 洛谷P2680运输计划

    传送门啦 要求的就是,把树上的一条边的权值设为0之后,所有路径中的最大值的最小值. 首先二分最大值,假设某次二分的最大值为x,我们首先找出所有大于x的路径(也就是我们需要通过改权缩短的路径),并把路径 ...

  5. Code Conventions for the JavaScript Programming Language

    This is a set of coding conventions and rules for use in JavaScript programming. It is inspired by t ...

  6. 使用T-SQL导入多个文件数据到SQL Server中

    在我们的工作中,经常需要连续输入多个文件的数据到SQL Server的表中,有时需要从相同或者不同的目录中,同时将文件中的数据倒入.在这篇文章中,我们将讨论如何同时把一个目录中的文件的数据倒入到SQL ...

  7. Python decorator装饰器

    问题: 定义了一个新函数 想在运行时动态增加功能 又不想改动函数本身的代码 通过高阶段函数返回一个新函数 def f1(x): return x*2 def new_fn(f): #装饰器函数 def ...

  8. Python创建ES索引

    # pip install elasticsearch from datetime import datetime from elasticsearch import Elasticsearch es ...

  9. 矩阵链乘(UVa 442)

    结构体 struct matrix 用来保存矩阵的行和列: map<string,matrix> 用来保存矩阵名和相应的行列数: stack<string> 用来保存表达式中遇 ...

  10. 在ASP.NET Web API和ASP.NET Web MVC中使用Ninject

    先附上源码下载地址 一.准备工作 1.新建一个名为MvcDemo的空解决方案 2.新建一个名为MvcDemo.WebUI的空MVC应用程序 3.使用NuGet安装Ninject库   二.在ASP.N ...