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

Re:最后的循环忘了跳出了,o(╥﹏╥)o

Posted by handake at 2020-11-24 11:19:47 on Problem 2251
In Reply To:Re:求解答 为啥一直WA Posted by:handake at 2020-11-24 11:19:00
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int n,m,h,a[20][20][20]={0},soux,souy,souz,desx,desy,desz,x,y,z;		//定义相关变量 
char st[20];
int xs[100],ys[100],zs[100];
int u[7] = {0,0,1,0,-1,0,0},				//三个方向 
	w[7] = {0,1,0,-1,0,0,0},
	v[7] = {0,0,0,0,0,1,-1};
int head,tail,num[100];

int main(){
	while((cin>>n>>m>>h)&&n&&m&&h){				//都为0时停止   输入长宽高三个参数 
		for(int i = 1;i<=n;i++){				//
			for(int j = 1;j<=m;j++){
				scanf("%s",st);					//输入一行的字符 
				for(int z = 1;z<=h;z++){
					if(st[z-1]=='S'){			//开始S开始字符标记  记录坐标 
						a[i][j][z] = 0;
						souz = i;
						souy = j;
						soux = z;
					}else if(st[z-1]=='.'){		//能够通过标记为0 
						a[i][j][z] = 0;
					}else if(st[z-1]=='#'){		//不能通过标记为-1 
						a[i][j][z] = -1;
					}else if(st[z-1] == 'E'){	//结束字符标记为0 记录坐标 
						a[i][j][z] = 0;
						desz = i;
						desy = j;
						desx = z;
					}else
						 return 0;	 
				}
			}	
		}	
		head = 0;						//队首指针 
		tail = 1;						//队尾指针 
		bool f = 0;
		a[souz][souy][soux] = -1;		//将开始坐标标记第一步标记-1 
		zs[tail] = souz;				
		ys[tail] = souy;				//记录队尾指针的坐标 
		xs[tail] = soux;
		while(head<tail){
			head++;						//队首指针+1 
//				x = soux;		//x坐标,y坐标,z坐标	
//				y = souy;
//				z = souz;
				
				for(int i = 1;i<=6;i++){		//六个方向进行寻找 
					x = xs[head] + u[i];		//x坐标,y坐标,z坐标	
					y = ys[head] + w[i];
					z = zs[head] + v[i];
					if((x>0)&&(x<=h)&&(y>0)&&(y<=m)&&(z>0)&&(z<=n)&&(a[z][y][x]==0)){ 	//判断是否可以前进 
						tail++;					//队尾指针+1 
						zs[tail] = z;			//将符合条件的坐标存储到队尾指针指向的数组中 
						ys[tail] = y;
						xs[tail] = x;
						a[z][y][x] = -1;			//将走过的坐标标记为-1 
						num[tail] = num[head]+1;		//记录当前路径的步数 
					}
					if((x==desx)&&(y==desy)&&(z==desz)){		//到达出口 
						f = 1; 				
						cout<<"Escaped in "<<num[tail]<<" minute(s)."<<endl;//输出步数 
						break;
					}
					
				}
				if(f)
					break;
		}
		if(!f){					//如果不存在 输出 
			cout<<"Trapped!"<<endl;
		}
	}
	return 0; 
}

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