A. Statues
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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处就是WIN,否则就是Lose。

主角先走一步之后, 所有的S下落一层,M不能走S,而且每轮有9种走法:向周围八个地方移动,以及原地不动。

思路:

1、首先预处理出所有S下落的时间,对应设定一个vector<int >mp【i】【j】,表示点(i,j)处会出现落石的时间集合。

2、然后我们Bfs起点,一点一点向A走,如果能够走到,输出WIN,否则输出LOSE即可。

Ac代码:

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node
{int x,y,step;
}now,nex;
char a[10][10];
int vis[10][10];
vector<int >mp[10][10];
int fx[9]={0,0,1,-1,0,1,1,-1,-1};
int fy[9]={1,-1,0,0,0,1,-1,1,-1};
int n=8,m=8;
void Bfs(int sx,int sy)
{queue<node >s;now.x=sx;now.y=sy;s.push(now);memset(vis,0,sizeof(vis));vis[sx][sy]=1;while(!s.empty()){now=s.front();if(a[now.x][now.y]=='A'){printf("WIN\n");return ;}s.pop();for(int i=0;i<9;i++){nex.x=now.x+fx[i];nex.y=now.y+fy[i];nex.step=now.step;if(nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<m){if(i!=4&&vis[nex.x][nex.y]==1)continue;int flag=0;for(int k=0;k<mp[nex.x][nex.y].size();k++){if(nex.step==mp[nex.x][nex.y][k]||nex.step+1==mp[nex.x][nex.y][k])flag=1;}if(flag==0){nex.step+=1;s.push(nex);vis[nex.x][nex.y]=1;}}}}printf("LOSE\n");return ;
}
int main()
{for(int i=0;i<8;i++){scanf("%s",a[i]);}int sx,sy;for(int i=0;i<8;i++){for(int j=0;j<8;j++){if(a[i][j]=='M'){sx=i;sy=j;}if(a[i][j]=='S'){mp[i][j].push_back(0);for(int k=1;k<8;k++){int xx=i+k;int y=j;if(xx<8){mp[xx][y].push_back(k);}}}}}Bfs(sx,sy);
}

Codeforces 128 A Statues【预处理+Bfs】相关推荐

  1. CSU2112 Wells的明星生活 预处理BFS二分

    为涛爷约会女朋友加油!\(` o ')/ 题目非常长了: Wells和小姐姐正在浪漫的约会呢,Wells猛然得到最新消息,有若干狗仔团队正闻讯蜂拥而来(Wells毕竟还是蛮很有名气的嘛)-- Well ...

  2. 【CodeForces - 129C】Statues(思维,bfs)

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

  3. 转换地图 (康托展开+预处理+BFS)

    Problem Description 在小白成功的通过了第一轮面试后,他来到了第二轮面试.面试的题目有点难度了,为了考核你的思维能量,面试官给你一副(2x4)的初态地图,然后在给你一副(2x4)的终 ...

  4. nyoj999 师傅又被妖怪抓走了 (预处理+bfs+状态压缩)

    题目999 题目信息 执行结果 本题排行 讨论区 师傅又被妖怪抓走了 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 话说唐僧复得了孙行者,师徒们一心同体,共诣西方.自宝 ...

  5. poj3669 Meteor Shower(预处理+bfs)

    https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. 1 #include< ...

  6. Codeforces 718E Matvey's Birthday bfs

    题意 给一个长度为n的字符串s,字符集大小为m. 再建立一张n个点的图,其中串中第i个字符就对应图中第i个点. 对这张图连这样两种边: 若对于i,j,满足|i-j|<=1,在点i和点j之间连双向 ...

  7. CodeForces 786A Berzerk 博弈?BFS瞎搞

    ans[i][j] i号选手在位置j行动的结果. 预处理,将每位选手能够直接到达黑洞的点 ans[1][(n-a[1][i]+n) % n] = -1; 表示必赢的点 把这些点加入到队列,作为BFS的 ...

  8. Codeforces 540C Ice Cave (BFS)

    题目:http://codeforces.com/problemset/problem/540/C 代码: #include<stdio.h> #include<string.h&g ...

  9. codeforces Gargari and Permutations(DAG+BFS)

    1 /* 2 题意:求出多个全排列的lcs! 3 思路:因为是全排列,所以每一行的每一个数字都不会重复,所以如果有每一个全排列的数字 i 都在数字 j的前面,那么i, j建立一条有向边! 4 最后用b ...

  10. Codeforces D. Fair 多源BFS求最短路

    点击打开链接 D. Fair time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

最新文章

  1. python 真多线程_Python之路200个小例子,在线网页版来了,从此学习更方便!
  2. 合肥南站,你怎么这么棒?人民日报都夸你了!
  3. vscode remote ssh 重新连接_使用 VSCode 愉快地进行 R 远程开发
  4. 物化视图(materialized view) 实现数据迁移、数据定时同步
  5. sublime3环境
  6. AVDictionary结构体相关源码介绍
  7. 在线选课网站用什么服务器,高校网上选课系统 PC服务器替代小型机
  8. 高性能mysql 3 pdf下载_《高性能MySQL_第3版》PDF版本下载
  9. 有什么计算机应用基础的app,计算机应用基础软件
  10. 常用电子元器件参考资料(参数手册大全)
  11. 第六章 基于QT和DCMTK的Dicom 图像浏览器---Dicom视图类
  12. HEVC/H265编码原理
  13. 测试用例设计方法---场景法
  14. SPSS中的比较均值—均值分析过程
  15. 全年盘点:2017最酷的10家大数据初创公司
  16. 方维直播源码:修复BUG完整版(附代码)
  17. 爱上开源之一款查询docker容器启动命令的工具
  18. 计算方法:三次样条插值原理
  19. Shipping Grants
  20. python智慧树判断题_智慧树_Python数据分析与数据可视化_判断题答案

热门文章

  1. 语义标签(Semantic label)与多模态模型的一些关系
  2. 【论文笔记_知识蒸馏_目标检测_2022】Decoupled Knowledge Distillation
  3. idea中webapp无法添加到mian文件夹中
  4. Unity粒子系统-粒子光环
  5. 如何关闭笔记本电脑触摸板功能
  6. Python新手接了第一个副业单子,2小时完成:Python修正excel表格数据
  7. 《地球概论》(第3版)笔记 第二章 地球的宇宙环境
  8. [bzoj5332][bzoj5276][bzoj3994][莫比乌斯反演][三元环计数]旧试题/skyfall/约数个数和
  9. 计算机桌面设置,电脑怎么设置动态桌面
  10. 华为云ECS服务器上安装docker