首页 技术 正文
技术 2022年11月15日
0 收藏 623 点赞 3,552 浏览 2819 个字

Finding crosses

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1631 Accepted Submission(s): 868

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.

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

Output

For each test case, output the number of crosses you find in a line.

Sample Input

4 oo#o o### oo#o ooo# 4 oo#o o### oo#o oo#o 5 oo#oo oo#oo ##### oo#oo oo##o 6 ooo#oo ooo##o o##### ooo#oo ooo#oo oooooo 0

Sample Output

1 0 0 0

代码

const int maxn=55;
char map[maxn][maxn];
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int n;bool ok(int x,int y){
return x>=0&&x<n&&y>=0&&y<n;
}bool check(int x,int y){
int cnt=0;
for(int i=1;i<=25;i++){
int tmpc=0;
for(int j=0;j<4;j++){int xx=x+dx[j]*i,yy=y+dy[j]*i;if(ok(xx,yy) && map[xx][yy]=='#'){
tmpc++;
if(j%2==0){
if(yy>0&&map[xx][yy-1]=='#' || yy<n-1&&map[xx][yy+1]=='#')return false;
cnt++;
}
else {
if(xx>0&&map[xx-1][yy]=='#' || xx<n-1&&map[xx+1][yy]=='#')return false;
cnt++;
}
}
}
if(tmpc==0)break;
if(tmpc!=4)return false;
}
if(cnt%2==0&&cnt>0)return true;
else return false;
}int main(){
while(scanf("%d",&n)&&n){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)scanf(" %c",&map[i][j]);
}int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(map[i][j]=='#' && check(i,j))ans++;
}
}printf("%d\n",ans);}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850