hdu4414 Finding crosses
来源:互联网 发布:中银淘宝校园卡办理 编辑:程序博客网 时间:2024/06/05 09:04
Finding crosses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 822 Accepted Submission(s): 463
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
直接暴搜就可以了
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define MAXN 100char map[MAXN][MAXN],str[MAXN];int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}},n;int find(int x,int y,int d){ if(x==0||x==n-1||y==0||y==n-1) return -1; int ans=0; while(1) { x+=dir[d][0],y+=dir[d][1]; if(x<0||x>=n||y<0||y>=n||map[x][y]!='#') break; if(d==0||d==2) { if(map[x+dir[1][0]][y+dir[1][1]]=='#'||map[x+dir[3][0]][y+dir[3][1]]=='#') return -1; } else if(d==1||d==3) { if(map[x+dir[0][0]][y+dir[0][1]]=='#'||map[x+dir[2][0]][y+dir[2][1]]=='#') return -1; } ans++; } return ans;}int dfs(int x,int y){ int k0=find(x,y,0); if(k0==-1)return -1; int k1=find(x,y,2); if(k1==-1)return -1; if(k0!=k1)return -1; int k2=find(x,y,1); if(k2==-1)return -1; int k3=find(x,y,3); if(k3==-1)return -1; if(k2!=k3)return -1; if(!k0||!k1||!k2||!k3) return -1; return 1;}int main(){ int i,j; while(scanf("%d",&n)!=EOF&&n) { gets(str); for(i=0;i<n;i++) { for(j=0;j<n;j++) { map[i][j]=getchar(); } gets(str); } int ans=0; for(i=1;i<n-1;i++) for(j=1;j<n-1;j++) { if(map[i][j]=='#'&&dfs(i,j)==1) ans++; } printf("%d\n",ans); } return 0;}
- HDU4414:Finding crosses
- hdu4414 Finding crosses
- hdu4414 Finding crosses
- HDU4414 Finding crosses(AC)
- Finding crosses(hdu4414,枚举)
- 模拟-Finding crosses hdu4414 c++
- HDU4414 Finding crosses(模拟 || DFS)
- HDU4414 2012ACM/ICPC杭州赛区网络赛E Finding crosses
- 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
- Finding crosses (搜索)
- HDOJ 4414 Finding crosses 搜索
- 当java swing界面启动无法正常显示,当调整JFrame大小后才能全部显示子组件
- 在ios中运用core animation暂停和继续动画
- hdu4415 Assassin’s Creed
- 赖勇浩:推荐《Linux 多线程服务器端编程》
- “啃老”族,蹭住多久才算久?
- hdu4414 Finding crosses
- [二次开发]dede会员列表调用(企业、个人)
- 9.3 折半查找
- clip:rect('top', 'right', 'bottom', 'left')
- Jackson多态类型数据的反序列化
- hdu4417 Super Mario
- QT 多页面切换之QTabWidget
- 20130827组队赛Regionals 2012, North America - Greater NY
- 使用C/C++扩展Python zz