hdu4414Finding crosses 水题

来源:互联网 发布:电脑软件开发制作 编辑:程序博客网 时间:2024/04/28 12:31
#include<cstdio>#include<cstring>#include<iostream>using namespace std ;const int maxn = 50 ;char map[maxn][maxn] ;int n ;int dx[4] = {0 , 0 , 1 , -1} ;int dy[4] = {1 , -1 , 0 , 0} ;bool judge(int x , int y){   if(x < 1 || x > n || y < 1 || y > n)   return false ;   return true ;}int dfs(int x , int y , int len , int dd){    if(!judge(x , y) || map[x][y] != '#')return len ;    for(int i = 0;i < 4;i++)    if(i != dd && i != (dd^1))    {        int nx = dx[i] + x ;        int ny = dy[i] + y ;        if(judge(nx ,ny) && map[nx][ny] == '#')        return  0 ;    }    return dfs(x + dx[dd] , y + dy[dd] , len + 1 , dd) ;}int main(){    while(scanf("%d" , &n) && n)    {        for(int i = 1;i <= n;i++)        scanf("%s" , &map[i][1]) ;        int ans = 0 ;        for(int i = 1;i <= n;i++)          for(int j = 1;j <= n;j++)          if(map[i][j] == '#')          {              int t0 = dfs(i + dx[0] , j + dy[0] , 0 , 0) ;              int t1 = dfs(i + dx[1] , j + dy[1] , 0 , 1) ;              int t2 = dfs(i + dx[2] , j + dy[2] , 0 , 2) ;              int t3 = dfs(i + dx[3] , j + dy[3] , 0 , 3) ;              if(t0 >= 1 && t0 == t1 && t1 == t2 && t2 == t3)              ans++ ;          }        cout<<ans<<endl;    }    return  0 ;}

0 0
原创粉丝点击