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. FusionCharts的类 - 实例功能

    一.FusionCharts的类 - 实例功能 1.configure(name:string , value:string)  or  configure(configurations: Objec ...

  2. [FACT_采购信息]增加了延期天数

    [延期天数]是指的采购单上的货品交货日期 减 [厂家来货]单据货品第一次到货日期. [FACT_采购信息] SELECT p.[Purchase_ID] [采购单号ID], p.[Supply_No] ...

  3. java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class gnu.xml.dom.JAXPFactory的解决办法(图文详解)

    不多说,直接上干货! 问题详情 java.lang.UnsupportedOperationException: setXIncludeAware is not supported on this J ...

  4. rabbitmq 不发送ack消息如何处理: RabbitMQ 消息确认以及消息消费方处理消息时候抛出了异常以

    本篇的代码使用的前面两篇文章<RabbitMQ与Spring整合之消息生产方>和<RabbitMQ与Spring整合之消息消费方>的代码,这两篇文件里配置文件的名称不正确,不可 ...

  5. Java语法基础(2)

    一.变量与常量 1.标识符与关键字 (1). 标识符 标识符可以简单的理解为一个名字,用来标识类名.变量名.方法名.数组名.文件名的有效字符序列.如图所示. Java语言规定标识符由任意顺序的字母.下 ...

  6. Java基本语法和变量

    1基本语法 1.1 标识符.关键字 在程序中用于定义名称的都为标识符,如文件名称.类名称.方法名称或变量名称等. 在Java中标识符的定义格式由字母.数字._(下划线),$所组成,不能以数字开头, 不 ...

  7. js正则匹配获取文件名

    //获取文件名,不带后缀 var file_name=file_path.replace(/(.*\/)*([^.]+).*/ig,"$2"); //获取文件后缀 1.var Fi ...

  8. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  9. python之元组,列表和字典的区别

    Python语言包含6种内建的序列,其中,有两种主要的类型:列表和元组. 列表是可以修改的,而元组不可以,如果要添加或者删除某些元素,就只能用列表,为了限制某些元素,就会用到元组.一般来说,列表可以替 ...

  10. (转)SQL注入攻击简介

    如果你是做Javaweb应用开发的,那么必须熟悉那声名狼藉的SQL注入式攻击.去年Sony就遭受了SQL注入攻击,被盗用了一些Sony play station(PS机)用户的数据.在SQL注入攻击里 ...