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

题干:

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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/439699.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一步步编写操作系统 47 48 二进制程序运行方式

操作系统并不是在功能上给予用户的支持&#xff0c;这种支持是体现在机制上。也就是说&#xff0c;单纯的操作系统&#xff0c;用户拿它什么都做不了&#xff0c;用户需要的是某种功能。而操作系统仅仅是个提供支持的平台。 虽然我们是模仿linux来写一个黑屏白字的系统&#x…

百度顶会论文复现(1):课程概述

最近百度推出了一款重磅课程《全球顶会论文作者&#xff0c;28天免费手把手带你复现顶会论文》。这个课程真的是很硬核的课程&#xff0c;这里简单记录下自己的学习过程。 文章目录1. 课程设计思路和安排2. 课程大纲1. 课程设计思路和安排 课程设计思路如下&#xff0c;共分为…

【Codeforces - 127D】Password(思维,二分+字符串Hash)

题干&#xff1a; Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock be…

百度顶会论文复现(2):GAN综述

本节课主要是对GAN的发展进行了介绍&#xff0c;包括基本原理&#xff0c;训练方法&#xff0c;存在问题&#xff0c;改进以及应用场景等。实践作业则为手写数字生成。课程地址为&#xff1a;https://aistudio.baidu.com/aistudio/education/preview/493290。 文章目录1.什么是…

一步步编写操作系统 48 二进制程序的加载方式

接上节&#xff0c;程序头可以自定义&#xff0c;只要我们按照自己定义的格式去解析就行。也许我光这么一说&#xff0c;很多同学还是不能彻底明白如何自定义文件头&#xff0c;因为大多数同学都是用高级语言来写程序&#xff0c;即使用了偏底层的c语言&#xff0c;不同平台的c…

【Codeforces - 864D】Make a Permutation!(贪心,字典序)

题干&#xff1a; Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his arra…

百度顶会论文复现(3):视频分类综述

本节课主要是对视频分类的发展进行了介绍&#xff0c;包括任务与背景&#xff0c;分类方法&#xff0c;前沿进展等。课程地址为&#xff1a;https://aistudio.baidu.com/aistudio/course/introduce/1340?directly1&shared1。 文章目录1. 任务与背景2. 视频分类方法2.1 双流…

一步步编写操作系统 46 linux的elf可执行文件格式1

ELF文件格式依然是分为文件头和文件体两部分&#xff0c;只是该文件头相对稍显复杂&#xff0c;类似层次化结构&#xff0c;先用个ELF header从“全局上”给出程序文件的组织结构&#xff0c;概要出程序中其它头表的位置大小等信息&#xff0c;如程序头表的大小及位置、节头表的…

百度顶会论文复现(4):飞桨API详解

本节课主要是对飞桨常用API进行了介绍&#xff0c;课程地址为&#xff1a;https://aistudio.baidu.com/aistudio/education/group/info/1340。 文章目录1.飞桨API官网2. API使用介绍3. 飞桨模型操作1.飞桨API官网 官网地址为&#xff1a;https://www.paddlepaddle.org.cn/docu…

【Codeforces - 977D】Divide by three, multiply by two(思维构造)

题干&#xff1a; Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1 operations of the two kinds: divide the number xx by 33 (xx must be divisible by 33);multiply the numbe…

一步步编写操作系统 45 linux的elf可执行文件中的段和节

接上文&#xff0c;为了描述清楚文件格式的本质&#xff0c;咱们先从最基本的“段”说起。 程序中最重要的部分就是段&#xff08;segment&#xff09;和节&#xff08;section&#xff09;&#xff0c;它们是真正的程序体&#xff0c;是真真切切的程序资源&#xff0c;所以下…

视觉SLAM十四讲(3):三维空间刚体运动

本章需要掌握的知识点有&#xff1a;旋转矩阵&#xff0c;变换矩阵&#xff0c;四元数&#xff0c;欧拉角定义和数学表达&#xff1b;同时也要掌握Eigen库关于矩阵、几何模块的使用方法。 文章目录3.1 旋转矩阵3.1.1 点&#xff0c;向量和矩阵的关系3.1.2 坐标系间的欧式变换3.…

【CodeForces - 483C】Diverse Permutation(思维构造)

题干&#xff1a; Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of ndistinct positive integers not larger than n. Well denote as n the length of permutation p1,   p2,   ...,   pn. Your task is to find such…

一步步编写操作系统 47 elf格式文件分析实验

在上一节中&#xff0c;我们讲述了elf格式的部分理论知识&#xff0c;为什么是部分呢&#xff1f;因为我们本着“够用”的原则&#xff0c;只把我们需要了解的部分说完啦。不过&#xff0c;我相信大部分同学仅仅凭上一节中的理论知识还是领悟不到elf本质&#xff0c;咱们在本节…

百度飞桨顶会论文复现(5):视频分类论文之《Representation Flow for Action Recognition》篇

这次老师在课上总共领读了4篇分类论文&#xff0c;我这里分享其中的一篇论文&#xff0c;是关于使用神经网络对光流进行学习。 课程地址是&#xff1a;https://aistudio.baidu.com/aistudio/education/group/info/1340。 论文地址是&#xff1a;https://arxiv.org/abs/1810.014…

智能算法(GA、DBO等)求解零等待流水车间调度问题(NWFSP)

先做一个声明&#xff1a;文章是由我的个人公众号中的推送直接复制粘贴而来&#xff0c;因此对智能优化算法感兴趣的朋友&#xff0c;可关注我的个人公众号&#xff1a;启发式算法讨论。我会不定期在公众号里分享不同的智能优化算法&#xff0c;经典的&#xff0c;或者是近几年…

【蓝桥官网试题 - 算法提高】change(思维)

题干&#xff1a; 问题描述 数组A中共有n个元素&#xff0c;初始全为0。你可以对数组进行两种操作&#xff1a;1、将数组中的一个元素加1&#xff1b;2、将数组中所有元素乘2。求将数组A从初始状态变为目标状态B所需要的最少操作数。 输入格式 第一行一个正整数n表示数组中元…

一步步编写操作系统 50 加载内核3

接上节&#xff0c;在这里&#xff0c;我们把参数放到了栈中保存&#xff0c;大家注意到了&#xff0c;参数入栈的顺序是先从最右边的开始&#xff0c;最后压入的参数最左边的&#xff0c;其实这是某种约定&#xff0c;要不&#xff0c;为什么不先把中间的参数src入栈呢。既然主…

【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)

题干&#xff1a; The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator. There are 16 handles on the refrigerator door. Every handle can be in one of two states: open or closed. The refrige…

动手学无人驾驶(5):多传感器数据融合

本系列的前4篇文章主要介绍了深度学习技术在无人驾驶环境感知中的应用&#xff0c;包括交通标志识别&#xff0c;图像与点云3D目标检测。关于环境感知部分的介绍本系列暂且告一段落&#xff0c;后续如有需要再进行补充。 现在我们开启新的篇章&#xff0c;在本文中将会介绍无人…