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. CallContext的LogicalCallContext在多线程环境下面公用变量

    压根名听说过这个类的看这里:如何实现对上下文(Context)数据的统一管理 原来以为CallContext就可以直接在多线程环境下面共享使用的,今天突然想到:Asp.Net环境下面,设置来设置去的, ...

  2. Map-HashMap-LinkedHashMap-Map.Entry-Collections-可变参数

    一.Map 接口(java.util) 定义:public interface Map<K,V> 介绍:     (1)Map是一个接口,含有两个泛型,创建子类对象的时候,需要传递两个泛型 ...

  3. android 代码将数据库文件导出到sd卡

    public static void save() { String dbpath = "/data/data/tl.cac.view/databases/" +"afi ...

  4. 【虚拟机-远程链接】Azure Windows 虚拟机常见导致无法远程的操作

    对Azure虚拟机的一些操作可能会导致无法远程连接,本文罗列了以下导致不能远程连接的场景: 场景1 - 在虚拟机网卡配置中配置IP地址或MAC地址 场景2 - 远程桌面授权过期 场景3 - 误设置“不 ...

  5. Nginx 基本配置介绍

    一.什么是Nginx Nginx 是一个免费的,开源的,高性能的HTTP服务器和反向代理,以及IMAP / POP3代理服务器. Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻 ...

  6. 洛谷 P2038 无线网络发射器选址

    题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...

  7. BZOJ 4881: [Lydsy2017年5月月赛]线段游戏

    4881: [Lydsy2017年5月月赛]线段游戏 Time Limit: 3 Sec  Memory Limit: 256 MBSubmit: 164  Solved: 81[Submit][St ...

  8. ES6, Angular,React和ABAP中的String Template(字符串模板)

    String Template(字符串模板)在很多编程语言和框架中都支持,是一个很有用的特性.本文将Jerry工作中使用到的String Template的特性做一个总结. ES6 阮一峰老师有一个专 ...

  9. SAP数据中心概述

    文章目录 SAP数据中心内部的组成部分 SAP数据中心的安全性 SAP数据中心的绿色运营 SAP云平台编程环境 Jerry的前一篇文章企业数字化转型与SAP云平台介绍了SAP云平台在企业数字化转型中的 ...

  10. 数据分析R&Python-Rpy2包环境配置

    Rpy2环境配置 最近想将R整合到以flask为后端框架的web系统中,在服务器端做数据统计分析.需要将R语言整合到Python中,发现Python中的Rpy2可以调用R语言,所以花了一些时间配置了一 ...