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

忘了加getchar()了,害我WA了2次。。。。附代码参考。。。

Posted by crazy852456 at 2012-07-21 14:07:33 on Problem 2251
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
char map[66][66][66];
bool visit[66][66][66];
int op[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
int n,m,k;
typedef struct note
{
    int x;
    int y; 
    int z;       
    int step;    
}S;
int BFS(int a,int b,int c)
{
     S s;
     s.x=a;
     s.y=b;
     s.z=c;
     s.step=0;
     queue<S> q;
     q.push(s);
     while(!q.empty())
     {
          S temp,ts;
          ts=q.front();                
          q.pop();
          for(int i=0;i<6;i++)
          {            
              temp.x=ts.x+op[i][0];
              temp.y=ts.y+op[i][1];
              temp.z=ts.z+op[i][2];
              temp.step=ts.step+1;           
              if(!visit[temp.x][temp.y][temp.z]&&map[temp.x][temp.y][temp.z]!='#')            
              {
                  visit[temp.x][temp.y][temp.z]=true;
                  if(map[temp.x][temp.y][temp.z]=='E')
                       return temp.step;
                  q.push(temp);
              }
                 
          }         
     }
     return -1;
}
int main()
{
    int ans,i,j,pn,pm,pk;
    while(~scanf("%d%d%d",&n,&m,&k))
    {    
        if(!n&&!m&&!k)   break;
        memset(visit,0,sizeof(visit));
        memset(map,'#',sizeof(map));
        for(int i=1;i<=n;i++)
        {
           for(int j=1;j<=m;j++)
              for(int o=1;o<=k;o++)
              {
                  cin>>map[i][j][o];
                  if(map[i][j][o]=='S')
                  {
                      pn=i;
                      pm=j;
                      pk=o;                     
                  }
              }
              getchar();
        }    
        ans=BFS(pn,pm,pk);
        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