Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 超时，帮看下

Posted by dynamic_study at 2009-08-01 17:21:03 on Problem 3051
```#include<iostream>
#include<algorithm>
using namespace std;
#define maxn1 100
#define maxn2  1001
char map[maxn2][maxn1];
bool flag[maxn2][maxn1];
int n,m,cnt,min1;
int dir[4][2]=
{
0,1,
1,0,
0,-1,
-1,0
};

void dfs(int si,int sj,int ans)
{
int i;
if(sj<0||sj>=m||si<0||si>=n)
return ;
flag[si][sj]=false;
if(ans>min1)
min1=ans;
for(i=0;i<4;i++)
{
if(flag[si+dir[i][0]][sj+dir[i][1]]==true)
{
flag[si+dir[i][0]][sj+dir[i][1]]=false;
dfs(si+dir[i][0],sj+dir[i][1],ans+1);
flag[si+dir[i][0]][sj+dir[i][1]]=true;
}
}
}

int main()
{
int i,j,loop,maxx;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>map[i][j];
if(map[i][j]=='*')
flag[i][j]=true;
else
flag[i][j]=false;
}
}
maxx=-99999;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(flag[i][j]==true)
{
min1=-999999;
dfs(i,j,1);
if(maxx<min1)
maxx=min1;
}
}
}
cout<<maxx<<endl;
}
return 0;
}

```

Followed by: