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 sapphirebitter at 2017-08-18 20:47:21 on Problem 2251
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<vector>
using namespace std;
int l0,r0,c0;
const int maxn =41;
bool have;
vector <int> way;
char dun[maxn][maxn][maxn];
bool visit[maxn][maxn][maxn];///访问标记
const int dr[]= {-1,0,1,0,0,0}; ///向左上右下
const int dc[]= {0,1,0,-1,0,0};
const int dl[]= {0,0,0,0,1,-1};
struct node
{
    int r;
    int c,l;
    int step;
};
void bfs(node start)
{
    queue <node> q; /// BFS 队列
    node now,next; /// 定义2 个状态,当前和下一个
    start.step=0; /// 计数器清零
    q.push(start); /// 入队
    visit[start.l][start.r][start.c]=1; /// 访问标记
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(dun[now.l][now.r][now.c]=='E')
        {
            way.push_back(now.step);
            have=true;
            return;
        }
        for(int i=0; i<6; i++)
        {
            next.l=now.l+dl[i], next.r=now.r+dr[i],next.c=now.c+dc[i];
            next.step=now.step+1;
            if(dun[next.l][next.r][next.c]=='E'||dun[next.l][next.r][next.c]=='.'&&visit[next.l][next.r][next.c]==0)
            {
                visit[next.l][next.r][next.c]=1;
                ///printf("%d %d %d\n",next.l,next.r,next.c);
                q.push(next);
            }
        }
    }
    return;
}

int main()
{
    node s;

    while(~scanf("%d%d%d",&l0,&r0,&c0)&&l0)
    {
        memset(dun,0,sizeof(dun));
        getchar();
        for(int i=0; i<l0; i++)
        {
            for(int j=0; j<r0; j++)
            {
                gets(dun[i][j]);
                for(int k=0; k<c0; k++)
                {
                    if(dun[i][j][k]=='S')
                    {
                        s.l=i,s.r=j,s.c=k,s.step=0;
                    }
                }
            }
            getchar();
        }
        way.clear();
        have=false;
        int mins=10000000;
        memset(visit,0,sizeof(visit));
        bfs(s);
        if(!have)
            printf("Trapped!\n");
        else
        {
            for(vector<int> ::iterator it=way.begin();it!=way.end();++it)
                    mins=min(mins,*it);
            printf("Escaped in %d minute(s).\n",mins);
        }
    }
    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