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 |
40-43行总是编译出错。。# include<stdio.h> # include<stdlib.h> struct node { int x,y; }; struct node queue[50],record[5][5]; int map[5][5]; int dir[][2]={0,1,0,-1,1,0,-1,0}; void bfs() { int head,tail,i; struct node cur,next; head=tail=0; tail++; while(head<tail) { cur=queue[head++]; for(i=0;i<4;i++) { next.x=cur.x+dir[i][0]; next.y=cur.y+dir[i][1]; if(next.x>=0&&next.x<5&&next.y>=0&&next.y<5&&map[next.x][next.y]==0) record[next.x][next.y].x=cur.x; record[next.x][next.y].y=cur.y; if(next.x==4&&next.y==4) return; else { queue[tail++]=next; map[next.x][next.y]=1; }}}} void main() { int i,j,k,m,n; struct node cur; for(i=0;i<5;i++) for(j=0;j<5;j++) scanf("%d",&map[i][j]); cur.x=0; cur.y=0; queue[0]=cur; map[0][0]=1; bfs(); k=0; i=j=4; queue[k].x=4; queue[k++].y=4; while(i!=0||j!=0) { m=i;n=j; i=record[m][n].x; j=record[m][n].y; queue[k].x=i; queue[k++].y=j; } for(i=k-1;i>=0;i--) printf("(%d,%d)\n",queue[i].x,queue[i].y); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator