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> using namespace std; #define N 1010 #define MAX(a,b) ( a > b ) ? a: b; struct item { int x,y; int step; }; char map[N][N]; int m,n; int result; item q[20000000],tt,maxNode,begin; int rear,front,maxstep,g,h; int go[N][N]; int go2[N][N]; item dir[4]={{-1,0},{0,1},{1,0},{0,-1},}; void BFS() { int i; memset(go,0,sizeof(go)); rear=front=0; q[rear++]=begin; go[begin.x][begin.y]=1; maxstep=1; while(front<rear) { tt=q[front++]; for(i=0;i<4;i++) { g=tt.x+dir[i].x; h=tt.y+dir[i].y; if(g<0||h<0||g>=m||h>=n) continue; if(!go[g][h]&&map[g][h]=='.') { go[g][h]=tt.step+1; q[rear].x=g; q[rear].y=h; q[rear++].step=tt.step+1; if(q[rear-1].step>maxstep) { maxstep=tt.step+1; } } } } } int main() { bool flag; // freopen("1.txt","r",stdin); int ca; int i,j; scanf("%d",&ca); while(ca--) { scanf("%d%d",&n,&m); for(i=0;i<m;i++) { scanf("%s",map[i]); } result=0; flag=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(map[i][j]=='.') { begin.x=i; begin.y=j; begin.step=1; flag=1; BFS(); break; } } if(flag) break; } result=MAX(result,maxstep-1); int temp=maxstep; for(i=0;i<m;i++) for(j=0;j<n;j++) go2[i][j]=go[i][j]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(go2[i][j]==temp) { begin.x=i; begin.y=j; BFS(); result=MAX(result,maxstep-1); } } } printf("Maximum rope length is %d\n",result); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator