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

1.队列开小了 2.输入顺序反了

Posted by vici at 2010-07-07 16:39:12 on Problem 2251 and last updated at 2010-07-07 16:39:38
In Reply To:谁要找出我代码哪儿错了、、、、姐姐给他买糖吃~ Posted by:Moon_1st at 2010-07-07 15:45:27
//修改后
#include <iostream>
using namespace std;

const int px[6]={0,0,0,0,1,-1};
const int py[6]={0,0,-1,1,0,0};
const int pz[6]={1,-1,0,0,0,0};
struct Point
{
   int x,y,z,length;       
}d[100000];
int l,r,c;
char map[40][40][40];
bool visit[40][40][40];

int bfs(int xx,int yy,int zz)
{
   int i,s,t,ans,x,y,z;
   memset(visit,false,sizeof(visit));
   memset(d,0,sizeof(d));
   visit[xx][yy][zz]=1;
   d[0].x=xx,d[0].y=yy,d[0].z=zz; 
   s=t=0;    
   while(s<=t)
   {
      for(i=0;i<6;i++)
      {
         x=d[s].x+px[i];
         y=d[s].y+py[i];
         z=d[s].z+pz[i];
         if(!visit[x][y][z]&&(map[x][y][z]=='.'||map[x][y][z]=='E'))
         {
            visit[x][y][z]=true;
            d[++t].x=x;
            d[t].y=y;
            d[t].z=z;
            d[t].length=d[s].length+1;
            if(map[x][y][z]=='E')
              return d[t].length;                                      
         }                 
      } 
      s++;          
   }
   return -1;
}

int main()
{
   int i,j,k,sx,sy,sz,ans;
   while(scanf("%d%d%d",&l,&r,&c)!=EOF)
   {
      if(l==0||r==0||c==0) break;
      memset(map,0,sizeof(map));

        for(i=1;i<=l;i++)
          for(j=1;j<=r;j++)
           for(k=1;k<=c;k++)
          {
             cin>>map[i][j][k];
             if(map[i][j][k]=='S')
             {
               sx=i;
               sy=j;
               sz=k;               
             }
          }                 
      ans=bfs(sx,sy,sz);  
      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