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矩阵,一头到一头,有雕塑会一秒下降一个
思路:搜索,记录每一个格子的每一秒是否有雕塑的情况
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-10
const int maxn=;
const int mod=1e9+; char mat[][];
bool vis[][];
bool dang[][][]; bool ok(int x, int y, int t)
{
if (x < || x > || y < || y > || dang[x][y][t] || vis[x][y])
{
return ;
}
return ;
} bool dfs(int x, int y, int t)
{
if (dang[x][y][t])
{
return ;
}
if (x == && y == )
{
return ;
}
for (int dx = -; dx <= ; dx++)
{
for(int dy=-;dy<=;dy++)
{
int xx = x + dx;
int yy = y + dy;
if (!ok(xx, yy, t))
{
continue;
}
vis[xx][yy] = ;
if (dfs(xx, yy, t + ))
{
return ;
}
vis[xx][yy] = ;
}
}
if (t <=)
{
if (dfs(x, y, t + ))
{
return ;
}
}
return ;
} int main()
{
while (~scanf("%s", mat[]))
{
for (int i = ; i < ; ++i)
{
scanf("%s", mat[i]);
}
memset(dang, , sizeof(dang));
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; ++j)
{
if (mat[i][j] == 'S')
{
dang[i][j][] = ;
int k = i + , t = ;
while (k < )
{
dang[k++][j][t++] = ;
}
}
}
}
memset(vis, , sizeof(vis));
vis[][] = ;
if (dfs(, , ))
{
printf("WIN\n");
}
else
{
printf("LOSE\n");
}
}
return ;
}

Statues CodeForces - 129C(bfs)的更多相关文章

  1. Amr and Chemistry CodeForces 558C(BFS)

    http://codeforces.com/problemset/problem/558/C 分析:将每一个数在给定范围内(10^5)可变成的数(*2或者/2)都按照广搜的方式生成访问一遍,标记上访问 ...

  2. Kilani and the Game CodeForces - 1105D (bfs)

    Kilani is playing a game with his friends. This game can be represented as a grid of size n×mn×m, wh ...

  3. codeforces #Round354-div2-D(BFS)

    题目链接:题目链接 题意:一个n*m的区域,每个格子都有上下左右四个门,相邻的两个格子A可以通向B当且仅当A对B的门和B对A的门都打开,问从起点S到终点T需要的最短时间 #include<bit ...

  4. Fire Again CodeForces - 35C (BFS)

    After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows ...

  5. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  6. 【算法导论】图的广度优先搜索遍历(BFS)

    图的存储方法:邻接矩阵.邻接表 例如:有一个图如下所示(该图也作为程序的实例): 则上图用邻接矩阵可以表示为: 用邻接表可以表示如下: 邻接矩阵可以很容易的用二维数组表示,下面主要看看怎样构成邻接表: ...

  7. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

  8. 【BZOJ5492】[HNOI2019]校园旅行(bfs)

    [HNOI2019]校园旅行(bfs) 题面 洛谷 题解 首先考虑暴力做法怎么做. 把所有可行的二元组全部丢进队列里,每次两个点分别向两侧拓展一个同色点,然后更新可行的情况. 这样子的复杂度是\(O( ...

  9. 深度优先搜索(DFS)和广度优先搜索(BFS)

    深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...

随机推荐

  1. ORA-06502 when awr report produce

    最近在生成一套系统的AWR报告时出现了如下报错:ORA-06502: PL/SQL: numeric or value error: character string buffer too small ...

  2. STM32空闲中断

    收发共存的思路没有经过验证!!! 空闲中断:既可以用来作为不定长接收数据帧的断帧判断/特别是DMA数据的接收,也可以用来指示中断发送的结束. 在需要发送的地方USART_ITConfig(UART5, ...

  3. python之简单登陆

    简单的登陆 要求: 1.用户名输错3次,系统退出 2.密码输错3次,账号被禁用 3.使用文件操作知识 流程图: 项目代码: def login(): i=0 while i <3 : name ...

  4. 一般处理程序aspx

    public bool IsReusable { get { return false; } }属性,将该属性的值改为true,为什么不起作用?按照MSDN的解释,该属性的意思是: “获取一个值,该值 ...

  5. 手机QQ访问时,html页面在QQ中自定义预览和自定义分享

    手机QQ访问时,html页面在QQ中自定义预览和自定义分享 有一天,产品说要做个自定义预览和分享功能,于是很快在微信上实现了,可是不知道在QQ上怎么实现,查看了很多网站,最后才找到了解决方案,于是想和 ...

  6. getuser

    Help on function getuser in module getpass: getuser()    Get the username from the environment or pa ...

  7. SAP ERP classification和C4C的同步

    在ERP里创建两个characteristic: 创建一个class包这两个characteristic.Class type 002意为该class能用于equipment. replicate到C ...

  8. SAP CRM和C4C的客户主数据修改历史记录查询

    SAP CRM 随便修改一个字段,比如给Search Term维护值"webpack": Change History assignment block里显示出了这条修改记录: 根 ...

  9. CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)

    根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...

  10. python_80_模块定义导入优化实例

            运行结果 __import__作用: 同import语句同样的功能,但__import__是一个函数,并且只接收字符串作为参数,所以它的作用就可想而知了.其实import语句就是调用这 ...