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

看了很多人的,感觉写的一样啊? 为啥一直WA 求大神看看

Posted by csucyj at 2018-08-25 09:34:02 on Problem 2251
#include<iostream>
#include<vector>
#include<list>
#include<stack> 
#include<cstring>
#include<math.h>
#include<stdio.h> 
#include<sstream>
#include<iomanip>
#include<algorithm>
#include<map>
#include<string.h>
#include<string>
using namespace std;
#define N 41
#define Inf  99999
#define inf  -99999
 int n,row,column;
int to[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0} ,{-1,0,0}};
int visit[N][N][N];
char ch[N][N][N];
struct node{
	int x;
	int y;
	int z;
	int step;
}beg;
int  Bfs(node beg){
	list<node> ls;
	visit[beg.z][beg.y][beg.x] = 1;
	beg.step = 0;
	ls.push_back(beg) ;
	 while(!ls.empty()){
	 	    node now = ls.front(); 
		    ls.pop_front();		 
		   	node ne;
	 	 	ne.step  = now.step+1;
	 	 for(int i=0;i<6;i++){
	 	 	ne.x = now.x+to[i][0];
	 	 	ne.y= now.y+to[i][1];
	 	 	ne.z= now.z+to[i][2];
	 	 	if(visit[ne.z][ne.y][ne.x]==1||ch[ne.z][ne.y][ne.x]=='#'){
	 	 		continue;
	 	 	}
	 	 	if(ne.x<0||ne.x>column-1||ne.y<0||ne.y>row||ne.z<0||ne.z>n-1)
	 	 	continue;
	 	    if(ch[ne.z][ne.y][ne.x]=='E')	{
		   	  return ne.step;
		   } 
	 	 	ls.push_back(ne)	;
	 	 	visit[ne.z][ne.y][ne.x] = 1;
	 	 	
	 	 }
	 	 
	
	 }
	return -1;
		
} 


int main(){
  while(cin>>n>>row>>column){
  	if(n==0&&row==0&&column==0)
  	break;
  	 memset(visit,0,sizeof(visit));
  
  	 for(int i=0;i<n;i++){
  	 	for(int j=0;j<row;j++){
  	 		for(int k=0;k<column;k++){	 	
  	 			cin>>ch[i][j][k];		
  	 			if(ch[i][j][k]=='S'){
  	 			   beg.x =k;
  	 			   beg.y =j;
  	 			   beg.z = i;
  	 			}
  	 		
  	 		}
  	 	}
  	 }
  	 
  	 
  	 int end =  Bfs(beg);	 
  	 if(end==-1){
  	 	printf("Trapped!\n");
  	 }else
     printf("Escaped in %d minute(s).\n", end);
  }
	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