#include "stdio.h"
#include "stdlib.h"
struct queue
{
int x,y,z;
int steps;
struct queue *next;
};
main()
{
char ch[10][10][10];
int x1,y1,z1;
int x2,y2,z2;
int n;
int i,j,k;
int step;
char temp[10];
struct queue que,*p,*q,*tail;
while(scanf("%s%d",temp,&n)!=EOF)
{
getchar();
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
scanf("%c",&ch[i][j][k]);
ch[i][j][k]='{post.content}';
getchar();
}
scanf("%d%d%d",&z1,&y1,&x1);
scanf("%d%d%d",&z2,&y2,&x2);
getchar();
scanf("%s",temp);
if(x1==x2 && y1==y2 && z1==z2)
{
printf("%d 0\n",n);
continue;
}
que.next=NULL;
p=&que;
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1;q->y=y1;q->z=z1;
q->steps=0;
q->next=NULL;
p->next=q;
p=q;
tail=q;
ch[x1][y1][z1]='F';
while(1)
{
x1=p->x;y1=p->y;z1=p->z;step=p->steps;
if(x1<=n-2)
{
if(ch[x1+1][y1][z1]=='O')
{
ch[x1+1][y1][z1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1+1;q->y=y1;q->z=z1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
if(x1>=1)
{
if(ch[x1-1][y1][z1]=='O')
{
ch[x1-1][y1][z1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1-1;q->y=y1;q->z=z1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
if(y1<=n-2)
{
if(ch[x1][y1+1][z1]=='O')
{
ch[x1][y1+1][z1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1;q->y=y1+1;q->z=z1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
if(y1>=1)
{
if(ch[x1][y1-1][z1]=='O')
{
ch[x1][y1-1][z1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1;q->y=y1-1;q->z=z1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
if(z1<=n-2)
{
if(ch[x1][y1][z1+1]=='O')
{
ch[x1][y1][z1+1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1;q->y=y1;q->z=z1+1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
if(z1>=1)
{
if(ch[x1][y1][z1-1]=='O')
{
ch[x1][y1][z1-1]='F';
q=(struct queue*)malloc(sizeof(struct queue));
q->x=x1;q->y=y1;q->z=z1-1;
q->steps=step+1;
q->next=NULL;
tail->next=q;
tail=q;
}
if(q->x==x2 && q->y==y2 && q->z==z2)
{
printf("%d %d\n",n,q->steps);
break;
}
}
q=p->next;
free(p);
p=q;
que.next=p;
if(p==NULL)
{
printf("NO ROUTE\n");
break;
}
}
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
}
}
zoj.gz_ ZOJ_ZOJ 1016_max flow_zoj 1045_zoj.rar
版权申诉
115 浏览量
2022-09-24
12:56:17
上传
评论
收藏 1.17MB GZ 举报
JaniceLu
- 粉丝: 78
- 资源: 1万+