Finding crosses(hdu4414,枚举)

41 篇文章 0 订阅
5 篇文章 0 订阅

http://acm.hdu.edu.cn/showproblem.php?pid=4414

Finding crosses

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

Total Submission(s): 727    Accepted Submission(s): 409

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

 

Source

2012 ACM/ICPC Asia Regional Hangzhou Online

 

Recommend

liuyiding

 解析:求得十字形的数量

对每一个可能存在十字形的点一一讨论。

1.讨论其上下左右是否对称分布

2,判断其周边是否有杂质

*/

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include <iostream>
using namespace std;
const int maxn=55;
char ch[maxn];
int map[maxn][maxn];
int n;
int check(int i,int j,int d)
{
if(d==1)//判断左右方向上
  {if(map[i][j-1]==0&&map[i][j+1]==0)
    return 1;
   return 0;
  }
  if(d==0)//上下方向
  {if(map[i-1][j]==0&&map[i+1][j]==0)
     return 1;
   return 0;
  }
}
int find(int i,int j)
{  //printf("(I%d,J%d) ",i,j);
  int left=0,right=0,above=0,below=0;
   int k=j;
  while(k--,map[i][k]&&k>=1){left++;}//往左边历遍
     if(left==0)
     return 0;
    k=j;
 // printf("left==%d ",j-left);
  while(k++,map[i][k]&&k<=n){right++;}//右边
   if(right==0||right!=left)//要求边长大于3且左右对称
     return 0;
   k=i;
 // printf("right==%d ",right+j);
 while(k--,map[k][j]&&k>=1){above++;}//上
    if(above==0||above!=left)
     return 0;
   k=i;
 //printf("above==%d ",i-above);
  while(k++,map[k][j]&&k<=n){below++;}//下
   if(below==0||below!=above)
    return 0;
//printf("below==%d\n",below+i);
  for(int x=j-left;x<=j+right;x++)//横
   {  if(x==j)
        continue;
    if(!check(i,x,0))
     return 0;
    }
  for(int y=i-above;y<=i+below;y++)//纵向
   {  if(y==i)
       continue;
    if(!check(y,j,1))
     return 0;
   }
 return 1;
}
int main()
{
  int i,j;
   while(scanf("%d",&n)!=EOF&&n!=0)
   {
      memset(map,0,sizeof(map));
   for(i=1;i<=n;i++)
    {scanf("%s",ch);
    for(j=0;j<n;j++)
     {if(ch[j]=='#')
        map[i][j+1]=1;
     }
    }
int ans=0;
    for(i=1;i<=n;i++)
       for(j=1;j<=n;j++)
          if(map[i][j]==1&&find(i,j))ans++;//此时以(i,j)为中心向各个方向历遍
   printf("%d\n",ans);
   }
    return 0;
}


Finding bugs(寻找错误)是指在软件开发过程中,为了保证软件的质量和稳定性,通过一系列的测试和调试过程,找出软件中存在的错误和缺陷,并进行修复的活动。 寻找错误是软件开发过程中必不可少的一步。在软件开发过程中,无论是编写代码、设计界面还是实施功能,都可能出现各种各样的错误。这些错误可能导致软件无法正常运行、功能异常或者性能低下。为了及时发现和修复这些错误,需要进行系统而全面的错误寻找工作。 寻找错误的方法和技巧有很多种。其中一种常用的方法是黑盒测试。黑盒测试是指在不了解软件内部结构和具体实现的情况下,通过输入一些指定的测试用例,观察软件的输出结果,并与预期结果进行对比,从而判断软件是否存在错误。另外一种方法是白盒测试。白盒测试是指在了解软件内部结构和具体实现的情况下,通过对代码进行逐行逐句的检查,发现其中潜在的错误。 除了以上的方法,还可以使用自动化的测试工具来辅助寻找错误。这些工具能够模拟用户的操作,快速地执行大量的测试用例,并生成详细的测试报告,帮助开发人员准确定位和修复错误。 在寻找错误的过程中,要保持耐心和专注。有时候错误可能隐藏得很深,需要仔细地分析和调试。同时,还要注重记录和总结错误,以便后续的修复工作。 总之,寻找错误是软件开发过程中不可或缺的一环。通过系统而全面的测试和调试工作,可以及时发现和修复软件中存在的错误和缺陷,提高软件的质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值