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

久久不能AC,求大牛指点哪里错了

Posted by wangjian8006 at 2012-03-23 22:30:00 on Problem 2251
#include <iostream>
#include <queue>
using namespace std;

typedef struct{
	int v,k;
	char c;
}vnode;

vnode node[60000];
int vmax,first,last,l,r,c;
int dx[]={1,-1,0,0,0,0};
int dy[]={0,0,0,0,-1,1};
int dz[]={0,0,-1,1,0,0};

void bfs(){
	int xt,yt,zt,temp,z,x,y,vtemp;
	queue <int>q;
	
	q.push(first);

	while(!q.empty()){
		vtemp=q.front();
		q.pop();
		
		z=(node[vtemp].v-1)/(r*c);
		x=((node[vtemp].v-1)%(r*c))/(r+1);
		y=((node[vtemp].v-1)%(r*c))%c;

		for(int i=0;i<6;i++){
			zt=z+dz[i];
			xt=x+dx[i];
			yt=y+dy[i];
			temp=c*r*zt+xt*c+yt+1;
			if(zt>=0 && zt<l && xt>=0 && xt<r && yt>=0 && yt<c && node[temp].c!='#') {
				node[temp].k=node[vtemp].k+1;
				q.push(temp);
				node[temp].c='#';
			}
			if(temp==last) return;
		}
	}
}

int main(){
	int i,j,k;
	char ch[100];
	while(scanf("%d%d%d",&l,&r,&c)){
		if(l==0 && r==0 && c==0) break;
		vmax=0;
		for(i=0;i<l;i++){
			for(j=0;j<r;j++){
				scanf("%s",&ch);
				for(k=0;k<c;k++){
					node[++vmax].v=vmax;
					node[vmax].c=ch[k];
					node[vmax].k=0;

					if(ch[k]=='S') first=vmax;
					else if(ch[k]=='E') last=vmax;
				}
			}
		}
		bfs();
		if(node[last].k==0) printf("Trapped!\n");
		else printf("Escaped in %d minute(s).\n",node[last].k);
	}
	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