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

题目的数据范围给小了,这个题目就是坑爹!

Posted by fangkyo at 2013-03-12 00:01:30 on Problem 2251
一开始设置三维数组的范围均是30,结果WA,后来设置为50,还是WA,最后设置为60,奇迹发生了,居然A了。害的我检查了半天程序,想想这么简单的题目不应该写错丫。给个能通过的代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

int L,R,C;
struct Point{
    int level,row,col;
    int count;
    Point( int l=0, int r=0, int c=0, int ct=0 ) 
    : level(l), row(r), col(c), count(ct) {}
    void show() {
        cout << "level=" << level << ", row=" << row << ", col=" << col <<endl;
    }
    void move( int dir[3], Point& pt ){
        pt.level = level + dir[0];
        pt.row = row + dir[1];
        pt.col = col + dir[2];
        pt.count = count+1;
    }
    
    bool inRange(){
        return  -1 < level && level < L &&
                -1 < row  && row < R &&
                -1 < col && col < C; 
    }
};

char d[60][60][60];
bool v[60][60][60];
Point s;

#define SETV( pt )  ( v[pt.level][pt.row][pt.col] = true )
#define GETV( pt )  v[pt.level][pt.row][pt.col]
#define GETCHAR( pt )  d[pt.level][pt.row][pt.col]

int dir[6][3] = {
    { 1, 0, 0 }, {-1, 0, 0 }, { 0, 1, 0 }, { 0,-1, 0 }, {0, 0, 1}, {0, 0, -1}
};

int bfs(){
    queue<Point> q;
    q.push(s);
    SETV( s );
    Point p, nextPt;
    while( !q.empty() ){
        p = q.front();
        q.pop();
        for( int i=0; i<6; ++i ){
            p.move( dir[i], nextPt );
            if( 'E' == GETCHAR( nextPt ) )
                return nextPt.count;
            if( nextPt.inRange() &&  '.' == GETCHAR(nextPt) && !GETV( nextPt ) ){
                SETV( nextPt );
                q.push( nextPt );
            }
        }
    }
    return 0;
}

int main(){
    char* str;
    char c;
    while( scanf( "%d%d%d", &L, &R, &C ), L ){
        for( int i=0; i<L; ++i ){
            for( int j=0; j<R; ++j ){
                
                str = d[i][j];
                scanf( "%s", str );
                for( int k=0; k<C; ++k ){
                    if( 'S' == str[k] ){
                        s.level = i;
                        s.row = j;
                        s.col = k;
                        s.count = 0;
                    }
                }

            }
        }
        
        memset( v, 0, sizeof(v) );
        int res = bfs();
        if( res )
            printf( "Escaped in %d minute(s).\n", res );
        else
            printf( "Trapped!\n" );
    }
    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