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

Re:Why always MLE!!!HELP!!!

Posted by 140410108 at 2017-02-18 23:20:01 on Problem 2251
In Reply To:Why always MLE!!!HELP!!! Posted by:remijohn at 2011-09-11 23:49:05
> #include<stdio.h>
> #include<queue>
> #include<string.h>
> using namespace std;
> 
> #define MAXNUM 31
> 
> struct _pos
> {
>   int x,y,l;
> };
> 
> _pos start,end;
> bool _map[MAXNUM][MAXNUM][MAXNUM];
> bool visit[MAXNUM][MAXNUM][MAXNUM];
> int path[MAXNUM][MAXNUM][MAXNUM];
> int l,r,c;
> 
> 
> 
> int BFS()
> {
>   queue<_pos> q;
>   _pos curPos,newPos;
>   curPos.x = start.x;
>   curPos.y = start.y;
>   curPos.l = start.l;
>   path[curPos.l][curPos.y][curPos.x] = 0;
> 
>   q.push(curPos);
>   int i;
>   int d[6][3] = {{0,-1,0},{1,0,0},{0,1,0},{-1,0,0},{0,0,-1},{0,0,1}};
>   while(!q.empty())
>     {
>       curPos = q.front();
>       visit[curPos.l][curPos.y][curPos.x] = true;
>       q.pop();
>       if(curPos.x == end.x && curPos.y == end.y && curPos.l == end.l)
> 	{
> 	  return path[curPos.l][curPos.y][curPos.x];
> 	}
>       for(i=0;i<6;i++)
> 	{
> 	  newPos.x = curPos.x + d[i][0];
> 	  newPos.y = curPos.y + d[i][1];
> 	  newPos.l = curPos.l + d[i][2];
> 	  if((newPos.x<0)||(newPos.x>c-1)||(newPos.y<0)||(newPos.y>r-1)||(newPos.l<0)||(newPos.l>l-1)||!_map[newPos.l][newPos.y][newPos.x]||visit[newPos.l][newPos.y][newPos.x])
> 	    continue;
> 	  path[newPos.l][newPos.y][newPos.x] = path[curPos.l][curPos.y][curPos.x] + 1;
> 	  q.push(newPos);
> 	}
>     }
>   return -1;
> }
> 
> int main()
> {
>   while(scanf("%d%d%d",&l,&r,&c) && l!=0 && r!=0 && c!=0 )
>     {
>       int i,j,k;
>       char temp;
>       for(i=0;i<l;i++)
> 	for(j=0;j<r;j++)
> 	  for(k=0;k<c;k++)
> 	    {
> 	      scanf(" %c",&temp);
> 	      if(temp == '#')
> 		_map[i][j][k] = false;
> 	      if(temp == '.')
> 		_map[i][j][k] = true;
> 	      if(temp == 'S')
> 		{
> 		  start.x = k;
> 		  start.y = j;
> 		  start.l = i;
> 		  _map[i][j][k] = true;
> 		}
> 	      if(temp == 'E')
> 		{
> 		  end.x = k;
> 		  end.y = j;
> 		  end.l = i;
> 		  _map[i][j][k] = true;
> 		}
> 	      memset(visit,false,sizeof(visit));
> 	    }
>       int ans = BFS();
>       if(ans == -1)
> 	printf("Trapped!\n");
>       else
> 	printf("Escaped in %d minute(s).\n",ans);
>     }
> 
>   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