| ||||||||||
| 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:不知道为什么WA,哪位帮忙看下??给点数据也行……In Reply To:不知道为什么WA,哪位帮忙看下??给点数据也行…… Posted by:42292624 at 2010-03-23 23:28:18 > #include<stdio.h>
> #include<string.h>
> #include<queue>
> using namespace std;
> char space[35][35][35];
> int dir[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};
>
> struct T
> {
> int level;
> int row;
> int col;
> };
> queue<T> q;
> T ori,des;
> bool flag;
> int Min;
> int l,r,c;
> int bfs();
> bool check(int ,int ,int);
>
> int main()
> {
> int i,j,k,m,n;
> int level,row,col;
> while(scanf("%d%d%d",&l,&r,&c)!=EOF&&(level+row+col))
> {
> for(i=1;i<=l;i++)
> {
> for(j=1;j<=r;j++)
> {
> getchar();
> for(k=1;k<=c;k++)
> {
> scanf("%c",&space[i][j][k]);
> if(space[i][j][k]=='S')
> {
> ori.level=i;
> ori.row=j;
> ori.col=k;
> }
> if(space[i][j][k]=='E')
> {
> des.level=i;
> des.row=j;
> des.col=k;
> }
> }
> }
> getchar();
> }
> while(!q.empty())
> q.pop();
> q.push(ori);
> space[ori.level][ori.row][ori.col]='#';
> flag=false;
> Min=0;
> Min=bfs();
> if(flag==false)
> printf("Trapped!\n");
> else
> printf("Escaped in %d minute(s).\n",Min);
> }
> return 0;
> }
> bool check(int level,int row,int col)
> {
> if(level>0&&level<=l&&row>0&&row<=r&&col>0&&col<=c&&space[level][row][col]!='#')
> return true;
> return false;
> }
>
> int bfs()
> {
> int i,j,k,m,n;
> T cur,next;
> while(!q.empty())
> {
> k=q.size();
> while(k--)
> {
> cur=q.front();
> q.pop();
> for(i=0;i<6;i++)
> {
> next.level=cur.level+dir[i][0];
> next.row=cur.row+dir[i][1];
> next.col=cur.col+dir[i][2];
> if(check(next.level,next.row,next.col))
> {
> if(next.level==des.level&&next.row==des.row&&next.col==des.col)
> {
> flag=true;
> Min++;
> return Min;
> }
> space[next.level][next.row][next.col]='#';
> q.push(next);
> }
> }
> }
> Min++;
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator