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 |
输出格式那个(s)好坑!!!为这个WA一次!那个(s),我以为是当数大于1的时候才输出s的意思呢。。。竟然是不管前面是不是1,都原样输出括号和s。。。简直大坑 #include <iostream> #include <queue> using namespace std; class pt{ public: int x,y,z; pt(int X,int Y,int Z): x(X),y(Y),z(Z){} pt(){} }; int main() { int L,R,C; while(1){ cin >> L >> R >> C; if(L == 0) return L; pt *start, *end; bool rock[32][32][32] = {false}; for(int i = 0; i < L; i++){ for(int j = 0; j < R; j++){ for(int k = 0; k < C; k++){ char c; cin >> c; if(c == '#') rock[i][j][k] = true; if(c == 'E') end = new pt(i,j,k); if(c == 'S') start = new pt(i,j,k); } } } int bushu[32][32][32] = {0}; bushu[start->x][start->y][start->z] = 1; queue<pt> qp; qp.push(*start); while(!qp.empty()){ pt tempPT = qp.front(); qp.pop(); int X = tempPT.x, Y = tempPT.y, Z = tempPT.z; int bs = bushu[X][Y][Z]; if(X>0 && !rock[X-1][Y][Z] && bushu[X-1][Y][Z]==0){ bushu[X-1][Y][Z] = bs+1; if(X-1 == end->x && Y == end->y && Z == end->z) break; qp.push(pt(X-1, Y, Z)); } if(X<L-1 && !rock[X+1][Y][Z] && bushu[X+1][Y][Z]==0){ bushu[X+1][Y][Z] = bs+1; if(X+1 == end->x && Y == end->y && Z == end->z) break; qp.push(pt(X+1, Y, Z)); } if(Y>0 && !rock[X][Y-1][Z] && bushu[X][Y-1][Z]==0){ bushu[X][Y-1][Z] = bs+1; if(X == end->x && Y-1 == end->y && Z == end->z) break; qp.push(pt(X, Y-1, Z)); } if(Y<R-1 && !rock[X][Y+1][Z] && bushu[X][Y+1][Z]==0){ bushu[X][Y+1][Z] = bs+1; if(X == end->x && Y+1 == end->y && Z == end->z) break; qp.push(pt(X, Y+1, Z)); } if(Z>0 && !rock[X][Y][Z-1] && bushu[X][Y][Z-1]==0){ bushu[X][Y][Z-1] = bs+1; if(X == end->x && Y == end->y && Z-1 == end->z) break; qp.push(pt(X, Y, Z-1)); } if(Z<C-1 && !rock[X][Y][Z+1] && bushu[X][Y][Z+1]==0){ bushu[X][Y][Z+1] = bs+1; if(X == end->x && Y == end->y && Z+1 == end->z) break; qp.push(pt(X, Y, Z+1)); } } int ans = bushu[end->x][end->y][end->z]; if(ans == 0) cout << "Trapped!" << endl; //else if(ans == 2) cout << "Escaped in " << 1 << " minute." << endl;这是个坑!!! else cout << "Escaped in " << ans-1 << " minute(s)." << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator