| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
好奇怪啊#include<queue>
#include<cstdio>
#include<map>
using namespace std;
struct point
{
int x,y,z,time;
point(int a=0,int b=0,int c=0,int t=0):x(a),y(b),z(c),time(t){}
};
struct pp
{
int x,y,z;
pp(int a = 0,int b = 0,int c = 0):x(a),y(b),z(c){};
bool operator<(const pp& an)const
{
if(x == an.x && y == an.y) return z<an.z;
if(x == an.x) return y<an.y;
return x<an.x;
}
};
map<pp,bool> my;
queue<point> myq;
int s[6][3] = {0,1,0,0,-1,0,0,0,-1,0,0,1,1,0,0,-1,0,0};
char graph[40][40][40];
int main(void)
{
int l,r,c;
while(scanf("%d%d%d",&l,&r,&c)==3)
{
my.clear();
while(!myq.empty())
myq.pop();
if(!l&&!r&&!c)
break;
int i,j,k;
point begin,end;
end.time = 0x7fffffff;
for(i=0;i<l;i++)
{
for(j=0;j<r;j++)
{
scanf("%s",graph[i][j]);
for(k=0;k<c;k++)
{
if(graph[i][j][k] == 'E')
{
end.x = i;
end.y = j;
end.z = k;
}
if(graph[i][j][k] == 'S')//找S的位置,这一句为真,也不进入
{
begin.x == i;
begin.y == j;
begin.z == k;
}
}
}
}
pp start(begin.x,begin.y,begin.z);
myq.push(begin);
my[start] = true;
while(!myq.empty())
{
begin = myq.front();
myq.pop();
start.x = begin.x;
start.y = begin.y;
start.z = begin.z;
if(begin.x == end.x && begin.y == end.y && begin.z ==end.z)
{
end.time = begin.time;
break;
}
for(i=0;i<6;i++)
{
if(begin.x+s[i][0]>=0&&begin.x+s[i][0]<l&&begin.y+s[i][1]>=0&&begin.y+s[i][1]<r&&begin.z+s[i][2]>=0&&begin.z+s[i][2]<c)
{
start.x = begin.x+s[i][0];
start.y = begin.y+s[i][1];
start.z = begin.z+s[i][2];
if(!my[start] && graph[start.x][start.y][start.z] != '#')
{
my[start] = true;
myq.push(point(start.x,start.y,start.z,begin.time+1));
}
start.x -= s[i][0];
start.y -= s[i][1];
start.z -= s[i][2];
}
}
}
if(end.time == 0x7fffffff)
puts("Trapped!");
else
printf("Escaped in %d minute(s).\n",end.time);
}
return 0;
}
/*
1 4 4
####
#S##
#E##
....*/
这个代码征对这一句,找不到S的位置,我郁闷,大家帮忙看看怎么回事啊
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator