HDU 4414 Finding crosses(暴力判断)
来源:互联网 发布:软件发明专利怎么写 编辑:程序博客网 时间:2024/05/22 04:29
Finding crosses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1262 Accepted Submission(s): 685
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.
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
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
4oo#o o###oo#oooo#4oo#o o###oo#ooo#o5oo#oooo#oo #####oo#oooo##o6ooo#ooooo##o o#####ooo#ooooo#oooooooo0
Sample Output
1000
1.十字架的长和宽相等
2.十字架相邻的不能出现#
AC代码:
#include <stdio.h>int n,ans;char a[55][55];void Ans(int i,int j){int l,r,u,d,flag=0;for(r=1;r<n-j;r++){if(a[i][r+j]=='#'){if(a[i+1][r+j]=='o'&&a[i-1][r+j]=='o')continue;else{flag=1;break;}}elsebreak;}for(l=1;l<=j;l++){if(a[i][j-l]=='#'){if(a[i+1][j-l]=='o'&&a[i-1][j-l]=='o')continue;else{flag=1;break;}}elsebreak;}for(u=1;u<=i;u++){if(a[i-u][j]=='#'){if(a[i-u][j-1]=='o'&&a[i-u][j+1]=='o')continue;else{flag=1;break;}}elsebreak;}for(d=1;d<n-i;d++){if(a[i+d][j]=='#'){if(a[i+d][j-1]=='o'&&a[i+d][j+1]=='o')continue;else{flag=1;break;}}elsebreak;}if(l==r&&l==u&&l==d&&l>1&&!flag)ans++;}int main(){int i,j;while(~scanf("%d",&n),n){ans=0;for(i=0;i<n;i++)scanf("%s",a[i]);for(i=1;i<n-1;i++)for(j=1;j<n-1;j++)if(a[i][j]=='#')Ans(i,j);printf("%d\n",ans);}return 0;}//5//o#o#o//###oo//o#o#o//oo###//ooo#o////5//o#o#o//###oo//o#o#o//o####//ooo#o////输出://2//0
0 0
- HDU 4414 Finding crosses(暴力判断)
- HDU 4414 Finding crosses 暴力枚举
- HDU ACM 4414 Finding crosses 暴力枚举
- HDU 4414 Finding crosses (暴力模拟)
- hdu-4414-Finding crosses
- hdu 4414 Finding crosses
- hdu 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414 Finding crosses
- HDU 4414: Finding crosses
- HDU 4414 Finding crosses(dfs)
- hdu 4414 Finding crosses(搜索)
- HDU 4414 Finding crosses(搜索)
- HDU 4414 Finding crosses(爆搜)
- hdu 4414Finding crosses(模拟)
- Finding crosses hdu 4414 dfs
- hdu 4414 Finding crosses 简单搜索
- 学习Spark第一天---1张图了解Spark
- 在tomcat下部署工程
- hdu 1716 排列2
- ZOJ2770 Burn the Linked Camp(差分约束)
- Flex基础知识入门--创建GISSever发布地地图显示
- HDU 4414 Finding crosses(暴力判断)
- C++ Primer 【第四版】第四章 数组和指针
- c#常见stream操作
- 关于字符编码,你所需要知道的
- 程序员的45个好习惯
- HDU 2289 Cup 二分
- 黑马程序员---------动态代理类与AOP
- Sed学习笔记
- C/C++编辑器Source Insight技巧收集