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

感觉没啥错啊5555 写了好多遍一直WA,求求大神解答!!

Posted by vanilla_12 at 2020-02-25 01:06:28 on Problem 2251
#include <iostream>
#include <cstdio> 
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std;
struct node{
	int ni,nj,nk;
	int dis;
};

int L,R,C;
int si,sj,sk;
int bOK=0;
char a[35][35][35];
int di[6]={1,-1,0,0,0,0};
int dj[6]={0,0,1,-1,0,0};
int dk[6]={0,0,0,0,1,-1};
int vis[35][35][35];

queue <node> q;

int bfs()
{
	node tmp;
	tmp.ni=si;
	tmp.nj=sj;
	tmp.nk=sk;
	tmp.dis=0;
	q.push(tmp);
	while(!q.empty())
	{
		node now=q.front();
		q.pop();
		int wi=now.ni,wj=now.nj,wk=now.nk,wdis=now.dis;
		for(int p=0;p<6;p++)
		{
			int oi=wi+di[p];
			int oj=wj+dj[p];
			int ok=wk+dk[p];
			if(oi<1||oi>L||oj<1||oj>R||ok<1||ok>C) continue;
			if(a[oi][oj][ok]=='#') continue;
			if(vis[oi][oj][ok]) continue;
			if(a[oi][oj][ok]=='E')
			{
					bOK=1;
			printf("Escaped in %d minute(s).\n",wdis+1);
			break;
			}
			tmp.ni=oi;
			tmp.nj=oj;
			tmp.nk=ok;
			tmp.dis=wdis+1;
			q.push(tmp);
			vis[oi][oj][ok]=1;
		}	
	} 
	return 0;
}

int main()
{
	cin>>L>>R>>C;
	while(L!=0||R!=0||C!=0)
	{
		memset(vis,0,sizeof(vis));
		bOK=0;
		 
		 for(int i=1;i<=L;i++)
   {
   	    for(int j=1;j<=R;j++)
   	    {
   	    	for(int k=1;k<=C;k++)
   	    	{
   	    		cin>>a[i][j][k];
   	    		if(a[i][j][k]=='S')
   	    		{
   	    			si=i;
   	    			sj=j;
   	    			sk=k;
				}
			}
		}
    }	
    
		bfs();
		if(bOK==0) printf("Trapped!\n");
		cin>>L>>R>>C;
	}
	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