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

求牛人赐教 ,数据都对,一直wa

Posted by s1270758234 at 2012-10-31 15:22:01 on Problem 2251
#include<iostream>
#include<queue>
#include<cstring>
#include<fstream>
using namespace std;


int L,R,C,mark,sum;
int bmp[6][3] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
int visited[35][35][35];
char map[35][35][35]; 

struct node{
	int x;
	int y;
	int z;
	int temp;
};

bool cheak(int a,int b,int c)
{
	if(a >= 1 && a <= L && b >= 1 && b <=R && c >= 1 && c <= C)
	return true;
	return false;
}
node first,nexta,top;
queue<node> vi;
void bfs(int a,int b,int c)
{
	mark = 0;
	first.x = a;
	first.y = b;
	first.z = c;
	first.temp = 0;
    vi.push(first);
    visited[first.x][first.y][first.z] = 1;
	
	while(!vi.empty())
	{
		top = vi.front();
		vi.pop();
		
			for(int i=0;i<6;i++){
				
				nexta.x = top.x + bmp[i][0];
				nexta.y = top.y + bmp[i][1];
				nexta.z = top.z + bmp[i][2];
				nexta.temp = top.temp;
		if(cheak(nexta.x,nexta.y,nexta.z) && !visited[nexta.x][nexta.y][nexta.z] && map[nexta.x][nexta.y][nexta.z] != '#')
		{
			if(map[nexta.x][nexta.y][nexta.z] == '.' )
			 nexta.temp ++;
		    if(map[nexta.x][nexta.y][nexta.z] == 'E')
		    {
		    	mark = 1;
    		   sum = nexta.temp+1;
			   return;	
    		}
    		visited[nexta.x][nexta.y][nexta.z] = 1;
    		vi.push(nexta);
			
		}
			}	
	}	
}
int main()
{
	ifstream cin("in.txt");
	while(cin>>L>>R>>C,L || R || C)
	{
		memset(visited,0,sizeof(visited));
		for(int i=1;i<=L;i++) 
		{
			for(int j=1;j<=R;j++){
				for(int k=1;k<=C;k++)
				cin>>map[i][j][k];
			}
		}
		for(int i=1;i<=L;i++)
		{
			for(int j=1;j<=R;j++){
				for(int k=1;k<=C;k++)
				if(map[i][j][k] == 'S')
				bfs(i,j,k);
			}
		}
		if(mark)
		cout<<"Escaped in "<<sum<<" minute(s)."<<endl;
		else
		cout<<"Trapped!"<<endl;
	}
}


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