题干:

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

题目大意:

给一个8*8的棋盘,左下角的人要走到右上角去(左下角为‘M’,右上角为‘A’),‘S’代表障碍物,每隔一秒障碍物会掉落一层,掉到最低层后的下一秒会掉出棋盘。对于每一秒,‘M’先走,障碍物再掉落。问‘M’能否走到‘A’处?

解题报告:

直接暴力bfs,剪枝如下:当步数>=8时,则一定成立。(如果改成步数>8,则会MLE,,输出了一下栈的大小是3e7左右,再加上结构体类型,确实会MLE)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
struct Node {int x,y,s;Node(int x=0,int y=0,int s=0):x(x),y(y),s(s){}
};
char s[11][11];
int nx[8] = {0,1,1,1,0,-1,-1,-1};
int ny[8] = {1,1,0,-1,-1,-1,0,1},maxsize;
bool bfs(int stx,int sty) {queue<Node> q;q.push(Node(stx,sty,0));while(q.size()) {Node cur = q.front();q.pop();if(s[max(1,cur.x-cur.s-1)][cur.y] != 'S') q.push(Node(cur.x,cur.y,cur.s+1));if(cur.s >= 8) return 1;for(int i = 0; i<8; i++) {int tx = cur.x + nx[i],ty = cur.y + ny[i];if(s[max(1,tx-cur.s-1)][ty] == 'S' || s[max(1,tx-cur.s)][ty] == 'S') continue;if(tx < 1 || tx > 8 || ty < 1 || ty > 8) continue;q.push(Node(tx,ty,cur.s+1));}}return 0;
}
int main()
{for(int i = 1; i<=8; i++) scanf("%s",s[i]+1); if(bfs(8,1) == 1) puts("WIN");else puts("LOSE");
//  printf("%d\n",maxsize);return 0 ;
}

【CodeForces - 129C】Statues(思维,bfs)相关推荐

  1. Orac and Game of Life CodeForces - 1350E(思维+BFS)

    Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with t ...

  2. Valid BFS? CodeForces - 1037D(思维 bfs)

    我真是一只菜狗......emm... 题意: 判断一个从1开始的队列是否可以按照bfs的顺序 进行遍历..必须从1开始...然后后边依次是bfs顺序 解析: 看代码能看懂吧...emm...就是把每 ...

  3. Statues CodeForces - 129C(bfs)

    In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the oppo ...

  4. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  5. CodeForces - 1534E Lost Array(bfs+交互)

    题目链接:点击查看 题目大意:初始时给出一个长度为 nnn 的序列,每次可以询问 kkk 个位置的异或和,现在需要以最少的询问获得整个序列的异或和 题目分析:因为是异或,我们只关心每个位置被询问的次数 ...

  6. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  7. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

  8. CodeForces - 1484D Playlist(循环链表+bfs)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列,规定其是一个首尾相接的环,不断的遍历该环,如果满足 gcd(ai,ai+1)==1gcd(a_i,a_{i+1})==1gcd(ai​,a ...

  9. CodeForces - 364A Matrix(思维+数学)

    题目链接:点击查看 题目大意:给出一个长度为 n 的,只由十进制数字组成的字符串 s,可以构造出一个大小为 n * n 的矩阵,构造方法如下:b[ i ][ j ] = s[ i ] * s[ j ] ...

最新文章

  1. Pytorch中的广播机制
  2. 因果表征学习最新综述:连接因果科学和机器学习的桥梁
  3. 《自然》:修复AI神经网络的缺陷
  4. sudo命令_用大写字母输入 Linux 命令,实现以 sudo 用户权限运行
  5. 【Leetcode | easy】最长公共前缀
  6. 解决com.xpand.. starter-canal 依赖引入问题
  7. 查看systemctl或service启动服务日志
  8. jasmine.any(Function)
  9. 谷歌浏览器地址栏记录怎么删除 Chrome浏览器地址栏记录清除方法
  10. c 获取mysql安装路径_linux查看mysql安装路径
  11. 使用NUnit做单元测试(总结版)
  12. 挂载jffs2文件系统遇到的问题
  13. 当前电子计算机发展的局限性,工程测量技术发展现状与趋势
  14. 雷云3启动无响应解决办法
  15. 【Paper reading】可变剪接预测ENCODEC数据集
  16. 2013电商十大新趋势
  17. Shadow Defender影子卫士
  18. 什么是网桥,它应该如何搭建
  19. linux清理缓存和垃圾,CentOS等Linux系统如何清理系统垃圾和日志?
  20. c# 路径下的最近文件夹_C# 添加Word水印(文本水印、图片水印)

热门文章

  1. CSS中class优先级问题
  2. Linux 命令平时积累
  3. [Leetcode][第32题][JAVA][最长有效括号][动态规划][栈][正向逆向结合]
  4. PHP与MySQL案例剖析_PHP与MySQL案例剖析
  5. hadoop元数据mysql中表字段_hive mysql元数据表说明
  6. 拆包--缓冲区查找包头及包尾偏移
  7. python注入点查找_sqlmap常用注入点检测爆破命令
  8. 1108D. Diverse Garland
  9. 7-8 德才论 (25 分)(C语言实现)
  10. python pp模块_python常用模块