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 bool_operator at 2017-06-10 15:16:04 on Problem 2251
RT,代码见下。。

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cstdlib>
using namespace std;
int x,y,z,lans,rans,ans;
bool ext;
char e[32][32][32];
bool vis[32][32][32];
int go[32][32][32];
int move[7][4]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
struct num{
    int x,y,z;
}start,tmp,where;
queue<num> q;

int check(int x,int y,int z){
    if(vis[x][y][z] || e[x][y][z]=='#') return 0;
    if(e[x][y][z]=='.') return 1;
    if(e[x][y][z]=='E') return -1;
}

void did(){
    switch(check(where.x,where.y,where.z)){
        case 1:
            vis[where.x][where.y][where.z]=1;
            q.push((num){where.x,where.y,where.z});
            go[where.x][where.y][where.z]=go[tmp.x][tmp.y][tmp.z]+1;
            break;
        case -1:
            go[where.x][where.y][where.z]=go[tmp.x][tmp.y][tmp.z]+1;
            printf("Escaped in %d minute(s).\n",go[where.x][where.y][where.z]);
            ext=1;
            break;
    }
}

int main(){
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
    
turn:
    //这两行初始化 
    memset(vis,0,sizeof(vis));
    while(!q.empty()) q.pop();
    ext=0;
    
    scanf("%d%d%d",&x,&y,&z);
    if(z==0 && x==0 && y==0) return 0;
    int i,j,k;
    for(i=0;i<x;i++)
       for(j=0;j<y;j++){
           scanf("%s",e[i][j]);
           for(k=0;k<z;k++)
               if(e[i][j][k]=='S') start.x=i,start.y=j,start.z=k;
       }
    
    q.push(start);
    vis[start.x][start.y][start.z]=1;
    while(!q.empty()){
        tmp=q.front();
        q.pop();
        for(i=0;i<6;i++){
            where.x=tmp.x+move[i][0],
            where.y=tmp.y+move[i][1],
            where.z=tmp.z+move[i][2];
            if(where.x<0 || where.x>=x || where.y<0 || where.y>=y || where.z<0 || where.z>=z) continue;
            //cout<<tmp.x<<' '<<tmp.y<<' '<<tmp.z<<"  ";
            //cout<<where.x<<' '<<where.y<<' '<<where.z<<' ';
            did();
            //cout<<e[where.x][where.y][where.z]<<'\n';
            if(ext) goto tz;
        }
    }
    printf("Trapped!\n");
tz:
    goto turn;
    return 0;
}
/*
3 4 5
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E
*/

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