12杭州online E 模拟
来源:互联网 发布:阿里云机房速度测试 编辑:程序博客网 时间:2024/05/03 20:39
Finding crossesTime Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
/*************************************************************************> File Name: e.cpp> Author:yuan > Mail: > Created Time: 2014年11月08日 星期六 20时10分39秒 ************************************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using namespace std;int n;char mat[53][53];int t1,t2,t3,t4;int cal(int x,int y){ for(int i=y;i<n;i++) { if(mat[x][i]=='o') break; t1++; } for(int i=y;i>=0;i--) { if(mat[x][i]=='o') break; t2++; } for(int i=x;i<n;i++) { if(mat[i][y]=='o') break; t3++; } for(int i=x;i>=0;i--) { if(mat[i][y]=='o') break; t4++; } if(t1!=t2) return -1; if(t3!=t4) return -1; if(t1<2||t3<2) return -1; return 1;}bool check(int x,int y){ int x1,y1; for(int i=1;i<=t1-1;i++) { x1=x,y1=y+i; if(mat[x1-1][y1]=='#') return 0; if(mat[x1+1][y1]=='#') return 0; } for(int i=1;i<=t1-1;i++) { x1=x,y1=y-i; if(mat[x1-1][y1]=='#') return 0; if(mat[x1+1][y1]=='#') return 0; } for(int i=1;i<=t3-1;i++) { x1=x+i,y1=y; if(mat[x1][y1-1]=='#') return 0; if(mat[x1][y1+1]=='#') return 0; } for(int i=1;i<=t3-1;i++) { x1=x-i,y1=y; if(mat[x1][y1-1]=='#') return 0; if(mat[x1][y1+1]=='#') return 0; } return 1;}int slove(){ int res=0; for(int i=1;i<n-1;i++) for(int j=1;j<n-1;j++) { t1=t2=t3=t4=0; if(mat[i][j]=='o') continue; int l=cal(i,j); if(l==-1) continue; if(check(i,j)) res++; } return res;}int main(){ while(1){ scanf("%d",&n); if(n==0) break; memset(mat,0,sizeof(mat)); for(int i=0;i<n;i++) { scanf("%s",mat[i]); } if(n<=2) {printf("0\n");continue;} int ans=slove(); printf("%d\n",ans); } return 0;}
0 0
- 12杭州online E 模拟
- e-模拟
- hdu4740【杭州网赛、模拟、有点搜索?】
- ZOJ 2969 模拟 (E)
- 模拟好题 E
- 杭州
- 杭州
- HDU 5937 && 2016CCPC杭州 E: Equation(DFS)
- CodeForces 412E - E-mail Addresses (模拟)
- Gym 100935E E. Pairs (模拟)
- codeforces-#469B. Chat Online(模拟)
- 模拟测试12.2中的move tablespace online
- 杭州电子科技大学Online Judge 之 “漂浮的气球(ID1004)”解题报告
- 杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告
- 杭州电子科技大学Online Judge 之 “水仙花数(ID2010)”解题报告
- 杭州电子科技大学Online Judge 之 “最大连续子序列(ID1231)”解题报告
- 杭州电子科技大学 Online Judge 之 “Max Sum PlusPlus(ID1024)”解题报告
- 杭州电子科技大学 Online Judge 之 “杨辉三角(ID2032)”解题报告
- 黑马程序员---------java多线程总结
- Java泛型详解
- svn提示:Invalid authz configuration
- 转:nginx 作为反向代理实现负载均衡的例子
- IIS7.5 如何完整看到500详细错误
- 12杭州online E 模拟
- jquery 之 selector 一
- Apache Commons IO简介
- android studio - swiperefreshlayout注意点
- hdu 4445 Crazy Tank(枚举)
- poj1008
- 第九周 下 项目5 求一年中第几天
- 适配器模式
- iOS 点击空白处键盘隐藏