Topic Portal
1 /*2 BFS: three-dimensional BFS, coordinates plus the number of steps, can walk a point when this place in the number of steps can not fall. Because the statue will fall in at most 8 steps,3 just make it through this time and win, or lose4 */5#include <cstdio>6#include <algorithm>7#include <queue>8#include <vector>9#include <cstring>Ten using namespacestd; One A Const intMAXN =Ten; - Const intINF =0x3f3f3f3f; - structpoint{ the intx, y, step; - }; - CharMAZE[MAXN][MAXN]; - BOOLVIS[MAXN][MAXN][MAXN]; + intN; - + BOOLCheckintXintYints) { A if(x >=1&& x <=8&& y >=1&& y <=8&& Maze[x-s][y]! ='S')return true; at return false; - } - - BOOLBFS (void) { -Queue<point> Q; Q.push (point) {8,1,0}); -memset (Vis,false,sizeof(Vis)); in - while(!Q.empty ()) { to intx = Q.front (). x, y = Q.front (). Y, S =Q.front (). Step; Q.pop (); + - if(S >8)return true; the if(Maze[x-s][y] = ='S')Continue; * $ for(inti=-1; i<=1; ++i) {Panax Notoginseng for(intj=-1; j<=1; ++j) { - inttx = x + i;intTy = y +J; the if(!check (TX, Ty, s))Continue; + if(!vis[tx][ty][s+1]) { Avis[tx][ty][s+1] =true; theQ.push (point) {TX, Ty, S +1}); + } - } $ } $ } - - return false; the } - Wuyi intMainvoid) {//codeforces Beta Round #94 (Div. 2 only) C. Statues the //freopen ("b.in", "R", stdin); - Wun =8; - while(SCANF ("%s", maze[1] +1) ==1) { About for(intI=2; i<=n; ++i) { $scanf ("%s", Maze[i] +1); - } - - if(BFS ())) puts ("WIN"); A ElsePuts ("lose"); + } the - return 0; $}
BFS codeforces Beta Round #94 (Div. 2 only) C. Statues