Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
超时,帮看下#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator