HDU 4414 Finding crosses
来源:互联网 发布:xampp apache正确方式 编辑:程序博客网 时间:2024/05/18 02:12
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
找十字架 旁边不能有别的东西
#include <stdio.h>char map[55][55];int main(){int n,i,j,ans,l1,l2,l3,l4,flag;while(~scanf("%d",&n),n){for(i=1;i<=n;i++)scanf("%s",map[i]+1);ans=0;for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(map[i][j]=='#'){//printf("%d %d %c\n",i,j,map[i][j]);l1=l2=l3=l4=1;flag=0;while(map[i][j-l1]=='#'){if(map[i-1][j-l1]=='#' || map[i+1][j-l1]=='#'){flag=1;break;}l1++;}if(flag)continue;while(map[i+l2][j]=='#'){if(map[i+l2][j-1]=='#' || map[i+l2][j+1]=='#'){flag=1;break;}l2++;}if(flag || l1!=l2)continue;while(map[i][j+l3]=='#'){if(map[i-1][j+l3]=='#' || map[i+1][j+l3]=='#'){flag=1;break;}l3++;}if(flag || l1!=l3)continue;while(map[i-l4][j]=='#'){if(map[i-l4][j-1]=='#' || map[i-l4][j+1]=='#'){flag=1;break;}l4++;}if(flag || l1!=l4)continue;if(l1==1)continue;ans++;}}}printf("%d\n",ans);}return 0;}
0 0
- 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 4414Finding crosses(模拟)
- Finding crosses hdu 4414 dfs
- HDU 4414 Finding crosses 暴力枚举
- hdu 4414 Finding crosses 简单搜索
- hdu 4414 Finding crosses【简单模拟】
- HDU 4414 Finding crosses (DFS + BFS)
- HDU 4414 Finding crosses(暴力判断)
- HDU 4414 Finding crosses(dfs)
- HDU ACM 4414 Finding crosses 暴力枚举
- hdu 4414 Finding crosses(搜索)
- HDU 4414 Finding crosses(搜索)
- 语料库
- 屏幕的适配
- 黑马程序员--IO流(操作对象、管道流、RandomAccessFile)
- window ip地址分配
- object references an unsaved transient instance - save the transient instance before flushing
- HDU 4414 Finding crosses
- 第五章 模版和Static Media
- fragment 详解(三)
- android中的异步加载
- 清除浮动
- 游戏的AOI算法
- 腾讯笔试题--删除set与vector中QQ号为奇数的号码
- Ashmem(匿名内存共享)
- CLAPACK