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

40-43行总是编译出错。。

Posted by Bonniejia at 2015-07-02 11:57:16 on Problem 3984
# 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator