hdu 1240 Asteroids!

入队错误,从昨天一直调到今天。先前在这句话

if((temp_x >=0 &&temp_x	< N)&&(temp_y >=0&&temp_y< N)&&(temp_z>=0 &&temp_z< N)&&!visited[temp_z][temp_y][temp_x]){}


是这样:

if(!visited[temp_z][temp_y][temp_x]&&(temp_x >=0 &&temp_x< N)&&(temp_y >=0&&temp_y< N)&&(temp_z>=0 &&temp_z< N)){}


RE了老半天。。。

#include <stdio.h>
#include <string.h> 
struct {
	int x,y,z;
}Q[1200];
int head,tail,step,add_step_flag;
char input[12][12][12];
int visited[12][12][12];
int end_x,end_y,end_z;
int N;
int could_come;
int  bfs(int begin_x,int begin_y,int begin_z){
	int dir[][3] = {
		{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}
	};
	int temp_x,temp_y,temp_z;
	
	if(begin_x== end_x&&begin_y == end_y&&begin_z == end_z){
		return 1;
	}else{
		for(int i = 0; i<6;++i){
			temp_x = begin_x+dir[i][0];
			temp_y = begin_y+dir[i][1];
			temp_z = begin_z+dir[i][2];
			if((temp_x >=0 &&temp_x	< N)&&(temp_y >=0&&temp_y< N)&&(temp_z>=0 &&temp_z< N)&&!visited[temp_z][temp_y][temp_x]){
					visited[temp_z][temp_y][temp_x] = 1;
					Q[tail].x = temp_x;
					Q[tail].y = temp_y;
					Q[tail].z = temp_z;
					++tail;
			}
		}
		++head;
		if(head == add_step_flag){
			++step;
			add_step_flag = tail;
		}
		if(head == tail){
			could_come = 0;
			return 0;
		}
		bfs(Q[head].x,Q[head].y,Q[head].z);
	}
	
}
int main(int argc, char *argv[])
{
	//FILE *fp;	
	//fp = freopen("in2.txt","r",stdin);
	

	char input_tem[11];
	while(~scanf("%s",input_tem)){
		scanf("%s",input_tem);
		if(input_tem[1] == '0'){
			N = 10;
		}else{
			N = input_tem[0] - '0';
		}
		for(int i = 0;i<N;++i){
			for(int j = 0;j<N;++j){
				scanf("%s",input[i][j]);
			}
		}
		memset(visited,0,sizeof(visited));
		memset(Q,0,sizeof(Q));
		for(int  i=0;i<N;++i){
			for(int j = 0;j<N;++j){
				for(int k = 0;k<N;++k){
					if(input[i][j][k]=='X'){
						visited[i][j][k] = 1;
					}
				}
			} 
		}
		
		scanf("%d%d%d",&Q[head].x,&Q[head].y,&Q[head].z);
		scanf("%d%d%d",&end_x,&end_y,&end_z);
		scanf("%s",input_tem); 
		head = 0;
		tail = 1;
		add_step_flag = 1;
		step = 0;
		could_come = 1;
	
		//if(bfs(Q[head].x,Q[head].y,Q[head].z)){
		visited[Q[head].z][Q[head].y][Q[head].x] = 1;
		 
		bfs(Q[head].x,Q[head].y,Q[head].z);
		if(could_come){
			printf("%d %d\n",N,step);
		}else{
			printf("NO ROUTE\n");
		}
		
	}
	return 0;
}


你可能感兴趣的:(hdu 1240 Asteroids!)