HDU4414
来源:互联网 发布:投资大师软件 编辑:程序博客网 时间:2024/06/05 15:20
Finding crosses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 394 Accepted Submission(s): 241
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
Source
2012 ACM/ICPC Asia Regional Hangzhou Online
Recommend
liuyiding
菜鸟就写写这种题了T.T
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int map[55][55];int n;int step[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};int ans;int len[4];bool pointt(int x,int y){ if(x>=0&&x<n&&y>=0&&y<n) return 1; else return 0;}void dfs(int s,int t,int x){ int it=s+step[x][0]; int jt=t+step[x][1]; if(pointt(s,t)&&map[s][t]) { if(x<2) { int i; for(i=2; i<4; i++) { int xt=s+step[i][0]; int yt=t+step[i][1]; if(!map[xt][yt]) continue; else { len[x]=-1; break; } } if(i==4) { len[x]++; dfs(it,jt,x); } } else { int i; for(i=0; i<2; i++) { int xt=s+step[i][0]; int yt=t+step[i][1]; if(!map[xt][yt]) continue; else { len[x]=-1; break; } } if(i==2) { len[x]++; dfs(it,jt,x); } } }}int main(){ char a[55]; while(cin>>n&&n) { ans=0; for(int i=0; i<n; i++) { cin>>a; for(int j=0; j<n; j++) if(a[j]=='#') map[i][j]=1; else map[i][j]=0; } for(int i=0; i<n; i++) for(int j=0; j<n; j++) { if(map[i][j]) { int p; for(p=0; p<4; p++) { int it=i+step[p][0]; int jt=j+step[p][1]; if(!map[it][jt]) break; } if(p==4&&!map[i-1][j-1]&&!map[i+1][j+1]&&!map[i-1][j+1]&&!map[i+1][j-1]) { for(int k=0; k<4; k++) { len[k]=0; dfs(i+step[k][0],j+step[k][1],k); } int k; for(k=1; k<4; k++) if(len[k]!=len[k-1]||len[k-1]==-1) break; if(k==4&&len[k-1]!=-1) ans++; } } } cout<<ans<<endl; } return 0;}
- HDU4414
- hdu4414
- HDU4414:Finding crosses
- hdu4414 字符串 模拟
- hdu4414 Finding crosses
- hdu4414 Finding crosses
- HDU4414 Finding crosses(AC)
- hdu4414(DFS 找十字架数量)
- Finding crosses(hdu4414,枚举)
- 模拟-Finding crosses hdu4414 c++
- HDU4414 Finding crosses(模拟 || DFS)
- HDU4414 2012ACM/ICPC杭州赛区网络赛E Finding crosses
- linearLayout 和 relativeLayout的属性区别
- fzu 1977 Pandora adventure(插头DP一条回路 格子的占用或不占用)
- hadoop中文文档
- 进入保护模式总结
- memcache的安装与使用
- HDU4414
- 大数n的阶乘
- yum安装提示正在运行
- ac自动机
- PE文件学习之一 文件内容的分部
- centos vsftp配置
- HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- 调试linux内核模块
- HTML5中的实用API