In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.

Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna’s square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.

At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.

Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.

Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is “.”. If a cell has Maria, then it is represented by character “M”. If a cell has Anna, it is represented by the character “A”. If a cell has a statue, then the cell is represented by character “S”.

It is guaranteed that the last character of the first row is always “A”, the first character of the last line is always “M”. The remaining characters are “.” or “S”.

Output
If Maria wins, print string “WIN”. If the statues win, print string “LOSE”.

Examples
Input
…A






M…
Output
WIN
Input
…A





SS…
M…
Output
LOSE
Input
…A




.S…
S…
MS…
Output
LOSE
题意:要从M走到A,不能走S。而且,M和所有的S交替走,M先走,S后走。M可以留在原地,也可以往八个方向走。S只能往下走。问能否走到A。
思路:反正就是8*8的一个图。直接暴力bfs就可以,记录一下走了多少步到达的这个点。以后再出现就不用重复这个情况了。而且在S是逐步下降的,还要注意走到这个点的时候有没有S降到这个点,或者这个点上一点就是S,都不行。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=10;
char s[maxx][maxx];
int mp[maxx][maxx][maxx];
int d[][2]={{0,0},{1,0},{1,1},{-1,0},{0,-1},{1,-1},{-1,1},{-1,-1},{0,1}};
struct node{int x,y,z;node(int a,int b,int c){x=a,y=b,z=c;}
};
int sx,sy,ex,ey;inline void bfs(int x,int y,int &flag)
{queue<node> q;q.push(node(x,y,0));mp[x][y][0]=1;while(q.size()){node a=q.front();q.pop();if(a.x==ex&&a.y==ey){flag=1;return ;}for(int i=0;i<9;i++){int tx=a.x+d[i][0];int ty=a.y+d[i][1];if(tx<0||tx>=8||ty<0||ty>=8) continue;if(s[tx][ty]=='S'&&a.z==0) continue;if((tx>=a.z+1&&s[tx-a.z-1][ty]=='S')||(tx>=a.z&&s[tx-a.z][ty]=='S')) continue;//这里注意,如果走到这一步的时候就是S,或者这一点上面就是S,就不能走了。if(mp[tx][ty][a.z+1]) continue;mp[tx][ty][a.z+1]=1;q.push(node(tx,ty,a.z+1));}}return ;
}
int main()
{for(int i=0;i<8;i++) scanf("%s",s[i]);for(int i=0;i<8;i++)for(int j=0;j<8;j++){if(s[i][j]=='M') sx=i,sy=j;if(s[i][j]=='A') ex=i,ey=j;}int flag=0;bfs(sx,sy,flag);if(flag) puts("WIN");else puts("LOSE");return 0;
}

努力加油a啊,(o)/~

Statues(三维bfs)相关推荐

  1. Dungeon Master(三维bfs)java

    题意: You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed o ...

  2. 胜利大逃亡 三维BFS

    Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个ABC的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0 ...

  3. Dungeon Master 三维BFS

    三维BFS DungeonMasterDungeon\ MasterDungeon Master 跟二维没啥区别,就是方向多了几个,但在写的过程中出的bugbugbug还是蛮多的,所以记录一下吧! # ...

  4. 【POJ2251】Dungeon Master(三维BFS)

    题面:[POJ2251]Dungeon Master 这是一道很有意思的题目,平时我们所接触的BFS大多是二维的,可这题不一样,这题是一道三维BFS!!! 这题不需要多讲,直接上代码就可以了: #in ...

  5. POJ 2251 Dungeon Master(三维BFS求最短路径)

    3D dungeon 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...

  6. poj 2251 Dungeon Master (三维bfs)

    http://poj.org/problem?id=2251 简单bfs,只不过是三维的... 唯一的坑点在输出上... Escaped in %d minute(s) 这意思是答案为1输出minut ...

  7. Dungeon Master(三维bfs)

    题目链接:http://poj.org/problem?id=2251 题目: Description You are trapped in a 3D dungeon and need to find ...

  8. 【CCCC】L3-004 肿瘤诊断 (30分),三维BFS

    problem L3-004 肿瘤诊断 (30分) 在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环.给定病灶扫描切片中标注出的疑似肿瘤区域,请你计算肿瘤的体积. 输入格式: 输入第一行给出4个正整数:M ...

  9. Dungeon Master(地牢大师、底下城主)三维bfs

    1253:Dungeon Master(地牢大师.底下城主) 要敢于变通 和普通bfs的区别,仅仅在于数组开三维+搜索方向多了上下(现在的搜索方向是 上下东南西北) bfs多组输入要记得清空队列 // ...

最新文章

  1. 常见linux命令使用方法(二)
  2. Building Shops dp 预处理距离
  3. html5option的js代码,ng-option(示例代码)
  4. android 开发 分辨率,Android手机应用开发为适应不同分辨率你应该知道的
  5. jquery.validate.js插件的使用方法
  6. swift button一些简单设置
  7. python array函数_Python 中的range()函数与array()函数
  8. Qt文档阅读笔记-FileDialog QML Type官方解析与实例
  9. OJ1090: 整数幂(多实例测试)(C语言)
  10. cssbefore图片大小_我可以在CSS:before /:after伪元素中更改图像的高度吗?
  11. 未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“***Form.resources”正确嵌入或链接到程序集“***”。。。
  12. Vue删除表格数据-调用逻辑
  13. pert图java_甘特图和PERT图
  14. Game boy模拟器(3):GPU的时序
  15. 孔雀优化算法(POA)——(含MATLAB代码)
  16. spring aop的术语
  17. JVM_12 垃圾回收3-垃圾回收器
  18. svg + image/svg+xml 文件上传实现xss
  19. ARM工控主板LS1012A
  20. NodeJs模块化(KPD)

热门文章

  1. sql server 2014安装方法教程
  2. ios 上传图片失败 小程序_iOS上传图片,就是有这种不一样的操作!
  3. 大数据翻页_【干货】大数据翻页的难点和技巧
  4. 斯坦福大学深度学习视频(CS231n课程)
  5. python爬取国内代理ip_Python语言爬取代理IP
  6. 框架鲜花商城系统测试_分销、团购、秒杀、优惠券小程序商城源码免费分享(Java语言)...
  7. 媒体查询常用屏幕分辨率参数
  8. Qt::WA_TransparentForMouseEvents用法
  9. C++11 统一初始化(Uniform Initialization)
  10. oracle 如果存在不创建表,oracle – 如果表不存在则创建表,并在创建后输入一行...