POJ 2251 Dungeon Master

其实编码时间用得较久,无明显异常。

提交发现一直的RuntimeError,查到是关于数组越界等错误,

猛然想起自己的队列开得不够大,最多30*30*30个点,硬是被我估算成9000,开个20000的队列还以为很大了,哎。。。

三维的广搜而已,广搜要记得涂每个点的层数,我是用结构体增加一个数据项step来实现的,这个考虑了比较久,不应该啊,之前应该写过类似的,不

总结很不好啊。

View Code
  1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 using namespace std;
5
6 struct Point
7 {
8 int x;
9 int y;
10 int z;
11 int step;
12 }start,end;
13
14 Point XPoint[29000];
15
16 int rear,top;
17
18
19 int level,column,row;
20 char map[32][32][32];
21 int dir[7][3]={{0,0,0},{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
22
23 #define ONLINE
24
25 void online()
26 {
27 #ifdef ONLINE
28 #else
29 freopen("F:\\t1.txt","r",stdin);
30 freopen("F:\\t2.txt","w",stdout);
31 #endif
32 }
33
34 int bfs(Point point)
35 {
36 if(rear>top)
37 return -1;
38 if(point.x==end.x&&point.y==end.y&&point.z==end.z)
39 {
40 return point.step;
41 }
42 for(int i=1;i<=6;i++)
43 {
44 Point temp;
45 temp.x=point.x+dir[i][0];
46 temp.y=point.y+dir[i][1];
47 temp.z=point.z+dir[i][2];
48 if(map[temp.z][temp.y][temp.x]=='#')
49 continue;
50 else
51 {
52 temp.step=point.step+1;
53 XPoint[++top]=temp;
54 map[temp.z][temp.y][temp.x]='#';
55 }
56 }
57 return bfs(XPoint[++rear]);
58 }
59
60 void init()
61 {
62 cin>>level>>row>>column;
63 while(level!=0||column!=0||row!=0)
64 {
65 memset(map,'#',sizeof(map));
66 memset(XPoint,0,sizeof(XPoint));
67 rear=top=0;
68 for(int zz=1;zz<=level;zz++)
69 for(int yy=1;yy<=row;yy++)
70 for(int xx=1;xx<=column;xx++)
71 {
72 cin>>map[zz][yy][xx];
73 if(map[zz][yy][xx]=='S')
74 {
75 start.x=xx;
76 start.y=yy;
77 start.z=zz;
78 start.step=0;
79 map[zz][yy][xx]='#';
80 }
81 if(map[zz][yy][xx]=='E')
82 {
83 end.x=xx;
84 end.y=yy;
85 end.z=zz;
86 }
87 }
88 int mininum=bfs(start);
89 if(mininum==-1)
90 cout<<"Trapped!"<<endl;
91 else
92 cout<<"Escaped in "<<mininum<<" minute(s)."<<endl;
93 cin>>level>>row>>column;
94 }
95 }
96
97 int main()
98 {
99 online();
100 init();
101 return 0;
102 }

 (1022,4D,继续2225?也是3DBF) 4D就是层层深入?

原文地址:https://www.cnblogs.com/YipWingTim/p/2224666.html