Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什么总是RE呢?高手来看下呀In Reply To:为什么总是RE呢?高手来看下呀 Posted by:zzczzc004 at 2008-08-06 17:44:23 > 如果去掉queue的头文件,自己写个队列就能过,为什么会这样? > > #include<stdio.h> > #include<stdlib.h> > #include<memory.h> > #include<queue.h> > > bool way[31][31][31],visited[31][31][31]; > int start_x,start_y,start_z,end_x,end_y,end_z; > /*class queue > { > private: > int a[100000]; > int head,rear,size; > public: > queue(){ > head=0,rear=0,size=0; > } > void push(int x){ > a[rear]=x; > rear=(rear+1)%100000; > size++; > } > int front(){ > return a[head]; > } > int empty(){ > return size==0; > } > void pop(){ > head=(head+1)%100000; > size--; > } > }; > */ > queue<int> q1_x,q1_y,q1_z,q2_x,q2_y,q2_z; > > int bfs() > { > int n=0,i,x,y,z; > q1_x.push(start_x); > q1_y.push(start_y); > q1_z.push(start_z); > while(!q1_x.empty()){ > while(!q1_x.empty()){ > x=q1_x.front(); > y=q1_y.front(); > z=q1_z.front(); > q1_x.pop(); > q1_y.pop(); > q1_z.pop(); > if(x==end_x && y==end_y && z==end_z){ > printf("Escaped in %d minute(s).\n",n); > return 1; > } > for(i=-1;i<=1;i++){ > if(way[x][y+i][z] && visited[x][y+i][z]){ > visited[x][y+i][z]=false; > q2_x.push(x); > q2_y.push(y+i); > q2_z.push(z); > } > if(way[x][y][z+i] && visited[x][y][z+i]){ > visited[x][y][z+i]=false; > q2_x.push(x); > q2_y.push(y); > q2_z.push(z+i); > } > if(way[x+i][y][z] && visited[x+i][y][z]){ > visited[x+i][y][z]=false; > q2_x.push(x+i); > q2_y.push(y); > q2_z.push(z); > } > } > } > while(!q2_x.empty()){ > q1_x.push(q2_x.front()); > q2_x.pop(); > q1_y.push(q2_y.front()); > q2_y.pop(); > q1_z.push(q2_z.front()); > q2_z.pop(); > } > n++; > } > return 0; > } > int main() > { > int l,r,c,i,j,k; > char s; > while(scanf("%d %d %d",&l,&r,&c)!=EOF,l|r|c){ > memset(way,false,sizeof(way)); > memset(visited,true,sizeof(visited)); > while(!q1_x.empty()){ > q1_x.pop(); > q1_y.pop(); > q1_z.pop(); > } > while(!q2_x.empty()){ > q2_x.pop(); > q2_y.pop(); > q2_z.pop(); > } > for(i=1;i<=l;i++){ > for(j=1;j<=r;j++){ > for(k=1;k<=c;k++){ > scanf(" %c",&s); > if(s=='.') > way[i][j][k]=true; > else{ > if(s=='S'){ > start_x=i,start_y=j,start_z=k; > visited[i][j][k]=false; > } > if(s=='E'){ > end_x=i,end_y=j,end_z=k; > way[i][j][k]=true; > } > } > } > } > } > if(!bfs()){ > printf("Trapped!\n"); > } > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator