杭电 oj 题目4414 Finding crosses
来源:互联网 发布:瞻博网络中国裁员 编辑:程序博客网 时间:2024/05/21 04:39
Finding crosses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2478 Accepted Submission(s): 1294
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<iostream>#include<cstring>#include<cstdio>using namespace std;int l;char matrix[55][55];int upper(int i,int j)//上{ int sum=0; while(i>=0) { if(matrix[i][j]!='#') break; if(matrix[i][j-1]!='o'||matrix[i][j+1]!='o') return -4; sum++; i--; } return sum;}int lower(int i,int j)//下{ int sum=0; while(i<l) { if(matrix[i][j]!='#') break; if(matrix[i][j-1]!='o'||matrix[i][j+1]!='o') return -3; sum++; i++; } return sum;}int left(int i,int j)//左{ int sum=0; while(j>=0) { if(matrix[i][j]!='#') break; if(matrix[i-1][j]!='o'||matrix[i+1][j]!='o') return -2; sum++; j--; } return sum;}int right(int i,int j)//右{ int sum=0; while(j<l) { if(matrix[i][j]!='#') break; if(matrix[i-1][j]!='o'||matrix[i+1][j]!='o') return -1; sum++; j++; } return sum;}int main(){ while(scanf("%d",&l)) { getchar(); if(l==0) break; memset(matrix,'o',sizeof(matrix)); for(int i=0;i<l;i++) { for(int j=0;j<l;j++) { scanf("%c",&matrix[i][j]); } getchar(); } int sum=0; for(int i=1;i<l-1;i++) { for(int j=1;j<l-1;j++) { if(matrix[i][j]=='#') { int upper1=upper(i-1,j); if(upper1==0) continue; int lower1=lower(i+1,j); if(upper1!=lower1) continue; int left1=left(i,j-1); if(left1==0) continue; int right1=right(i,j+1); if(left1!=right1) continue; sum++; } } } printf("%d\n",sum); } return 0;}
- 杭电 oj 题目4414 Finding crosses
- 杭电acm 4414 Finding Crosses dfs的运用
- 杭电 HDU 4414 Finding crosses 2012 ACM/ICPC 杭州网赛
- hdu-4414-Finding crosses
- hdu 4414 Finding crosses
- hdu 4414 Finding crosses
- HDOJ - 4414 (Finding crosses)
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414: Finding crosses
- HDOJ 4414 Finding crosses 搜索
- hdu 4414Finding crosses(模拟)
- Finding crosses hdu 4414 dfs
- hdoj 4414 Finding crosses 【枚举】
- HDU 4414 Finding crosses 暴力枚举
- hdu 4414 Finding crosses 简单搜索
- hdu 4414 Finding crosses【简单模拟】
- 利用python将多份excel表格整理成一份新表格
- 不同Content Type下的$.ajax请求
- [编辑器] MarkDown 编辑器的常用命令总结
- 遍历二叉树
- plusOne
- 杭电 oj 题目4414 Finding crosses
- Bean的装配(1)
- if和与、或的组合判断
- 变量+标量变量+变量命名规则+变量命名规则
- 存储结构的定义及其分类
- ASP.NET页面输出XML(C#)
- .NET 在线生成XML文档,并提供下载
- 多进程爬虫
- 专注于windows系统安全 与 asp.net开发