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 |
哪位大牛帮忙看看哪错了#include<iostream> using namespace std; int dir[][2] = {{1, 0},{0, 1},{-1, 0},{0, -1}}; int n; char map[100][12]; struct Node { int C, R; int M; int step; }queue[10000000], end; bool ok(int x, int y) { if(x < 0 || x >= n * n || y < 0 || y >= n) return false; return map[x][y] == 'O'; } int main() { char t[8], e[8]; while(1 == scanf("%s", t) ) { scanf("%d", &n); int i; for(i = 0; i < n * n; i ++) scanf("%s", &map[i]); scanf("%d %d %d", &queue[0].C, &queue[0].R, &queue[0].M ); queue[0].R += queue[0].M * n; queue[0].step = 0; scanf("%d %d %d", &end.C, &end.R, &end.M ); end.R += end.M * n; scanf("%s", e); int k = 0; int t = 1; bool res = false; while( t != k) { if(queue[k].R == end.R && queue[k].C == end.C) { res = true; break; } for(i = 0; i < 4; i ++) { if(ok(queue[k].R + dir[i][0], queue[k].C + dir[i][1])) { queue[t].step = queue[k].step + 1; queue[t].R = queue[k].R + dir[i][0]; queue[t].C = queue[k].C + dir[i][1]; map[queue[t].R][queue[t].C] = 'X'; t ++; } } k ++; } if(res) printf("%d %d\n", n, queue[k].step); else printf("NO ROUTE\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator