zoj1438-asteroids!

Source: Internet
Author: User

This question is completely changed according to zoj1940 a bit of input and output ... The code doesn't change much.

#include <iostream> #include <queue> #include <string> #include <memory.h> using namespace std;
Char maze[11][11][11]; const int pmove[4][2]={{0,1},{0,-1},{-1,0},{1,0}};//moves int z;//How many groups of int n;//how many rows int m;//how many columns int sx,sy,ex,ey,sz,ez; int Aste
Roids ();
	struct Node {friend bool operator < (node A,node b) {return a.step>b.step;
} int x,y,z,step;
};
	int main () {int i,j;
	String str;
		while (CIN&GT;&GT;STR) {cin>>n;
		M=z=n;
		Memset (Maze, ' X ', sizeof (maze));
		if (z==0&&n==0&&m==0) break;
		for (int. icase=0;icase<z;icase++) for (i=0;i<n;i++) for (j=0;j<m;j++) cin>>maze[icase][i][j];
		cin>>sx>>sy>>sz>>ex>>ey>>ez>>str;
		int tmp;
		Tmp=asteroids ();
		if (tmp!=-1) cout<<z<< ' <<tmp<<endl;
	else cout<< "NO ROUTE" <<endl;
} return 0;
	} int asteroids () {priority_queue<node> que;
	Node now,temp;
	int V;
	NOW.X=SX; Now.y=sy;
	Now.z=sz;
	Now.step=0;
	Que.push (now);
	maze[sz][sy][sx]= ' X ';
		while (!que.empty ()) {temp=que.top ();
		Que.pop ();
		if (Temp.x==ex&&temp.y==ey&&temp.z==ez) return temp.step; for (int i=0;i<z;i++)//Crossing {if (temp.z-1>=0) if (maze[temp.z-1][temp.y][temp.x]!= ' x ') {now=temp
						;
						now.z--;
						now.step++;
						Que.push (now);
						maze[temp.z][temp.y][temp.x]= ' x ';
					maze[temp.z-1][temp.y][temp.x]= ' x ';
						} if (Temp.z+1<z) if (maze[temp.z+1][temp.y][temp.x]!= ' x ') {now=temp;
						now.z++;
						now.step++;
						Que.push (now);
					maze[temp.z+1][temp.y][temp.x]= ' x '; }} for (v=0;v<4;v++)//Normal move {for (int i=0;i<z;i++)//Cross {if (temp.z-1>=0) if (maze[temp.z-1][
					temp.y][temp.x]== '. ')
						{now=temp;
						now.z--;
						now.step++;
						Que.push (now);
						maze[temp.z][temp.y][temp.x]= ' x ';
					maze[temp.z-1][temp.y][temp.x]= ' x '; } if (Temp.z+1<z) if (maze[temp.z+1][temp.y][temp.x]== '. ')
						{now=temp;
						now.z++;
						now.step++;
						Que.push (now);
					maze[temp.z+1][temp.y][temp.x]= ' x ';
			}} Now.x=temp.x+pmove[v][0];
			NOW.Y=TEMP.Y+PMOVE[V][1];
			Now.z=temp.z;
			now.step=temp.step+1;
			if (Now.x==ex&&now.y==ey&&temp.z==ez) return now.step; if (now.x<0| | now.y<0| | now.x>m| |
			Now.y>n) continue;
				if (maze[temp.z][now.y][now.x]!= ' x ') {Que.push (now);
			maze[temp.z][now.y][now.x]= ' x ';
}}} return-1; }


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.