hdu5024Wang Xifeng's Little Plot 暴力枚举

来源:互联网 发布:wifi攻击软件 编辑:程序博客网 时间:2024/05/17 04:02
//给一个n*n的图 ,找一条最多只有一个拐点//且在拐点的两条路的方向为90度//问这条路的最大长度//.表示路 , #表示墙//n<=100//直接暴力枚举所有的为拐点,从拐点延伸八个方向的长度//然后直接计算就行#include<cstdio>#include<cstring>#include<iostream>#include<queue>using namespace std ;const int maxn = 110 ;char str[maxn][maxn] ;int sum[8][maxn][maxn] ;int a[8] ;int dx[8] = {0 , -1 , -1 , -1 , 0 , 1 , 1 , 1} ;int dy[8] = {1 , 1 , 0 , -1 , -1 , -1 , 0 , 1};int flag = 0 ;int n ;int dfs(int di , int x , int y , int sum){    if(x < 1 || x > n || y < 1 || y > n || str[x][y] == '#')    return sum ;    dfs(di , x + dx[di] , y + dy[di] , sum+1) ;}int main(){    //freopen("in.txt" , "r" , stdin) ;    while(scanf("%d" , &n)&&n)    {        for(int i = 1;i <= n;i++)        scanf("%s" , &str[i][1]) ;        int ans = 0 ;        for(int i = 1;i <= n;i++)          for(int j = 1;j <= n;j++)          if(str[i][j] == '.')          {              for(int k = 0;k < 8;k++)              a[k] = dfs(k , i , j , 0) ;              ans = max(max(a[0],a[4])+max(a[2],a[6])-1 , ans) ;              ans = max(max(a[1],a[5])+max(a[3],a[7])-1 , ans) ;           }        cout<<ans<<endl;    }}

0 0