您的位置:首页 > 产品设计 > UI/UE

BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

2015-07-20 14:24 423 查看
题目传送门

 /*
BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到。因为雕像最多8步就会全部下落,
只要撑过这个时间就能win,否则lose
*/
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;

const int MAXN = 10;
const int INF = 0x3f3f3f3f;
struct Point{
int x, y, step;
};
char maze[MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int n;

bool check(int x, int y, int s)    {
if (x >= 1 && x <= 8 && y >= 1 && y <= 8 && maze[x-s][y] != 'S')   return true;
return false;
}

bool BFS(void)  {
queue<Point> Q;   Q.push ((Point) {8, 1, 0});
memset (vis, false, sizeof (vis));

while (!Q.empty ()) {
int x = Q.front ().x, y = Q.front ().y, s = Q.front ().step;    Q.pop ();

if (s > 8)  return true;
if (maze[x-s][y] == 'S')    continue;

for (int i=-1; i<=1; ++i)   {
for (int j=-1; j<=1; ++j)   {
int tx = x + i; int ty = y + j;
if (!check (tx, ty, s))    continue;
if (!vis[tx][ty][s+1])  {
vis[tx][ty][s+1] = true;
Q.push ((Point) {tx, ty, s + 1});
}
}
}
}

return false;
}

int main(void)  {       //Codeforces Beta Round #94 (Div. 2 Only) C. Statues
//freopen ("B.in", "r", stdin);

n = 8;
while (scanf ("%s", maze[1] + 1) == 1)  {
for (int i=2; i<=n; ++i)    {
scanf ("%s", maze[i] + 1);
}

if (BFS ()) puts ("WIN");
else    puts ("LOSE");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: