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".

这个明显的是搜索题。这个是属于障碍物会动的搜索题。这种情况下bfs比起dfs处理起来更方便了。因为BFS可以一步步来求,当然dfs求解这题也是可以的。

主要解题过程如下:开始从上往下从左往右先把节点全部编号为0~63。把当前可满足的点存起来,放在一个队列中,随便数组也可以。当然开始是只有当前点,即左下角那点。然后枚举八个方向,把满足的点放在另一个队列中,暂称为目标队列。重复7、8次,每一次记得要更改status的位置,发现某一次其中目标队列为空那么就是没路可走了,那就输了,否则就是赢。

AC代码:

#include <iostream>
#include <cstring>
#include <set>
#include <cstdio>
#include <string>
#include <queue>
using namespace std;
queue<int> q1, q2 ;
char g[20][20];
int vis[70];//是否已存在队列中
int exist[70];//是否为status
int x[8]={0, 0, 1, -1, 1, -1, 1, -1};
int y[8]={1, -1, 0, 0, 1, 1, -1, -1};
int main(){int i, j, k;for(i=0; i<8; i++){scanf("%s", g[i]);}memset(exist, 0, sizeof(exist));for(i=0; i<8; i++){for(j=0; j<8; j++){if(g[i][j]=='S'){exist[i*8+j]=1;}}}q1.push(56);for(i=1; i<=8; i++){if(i%2==0){memset(vis, 0, sizeof(vis));while(!q2.empty()){int num=q2.front(); q2.pop();if(!vis[num])if(num-8<0||!exist[num-8]){q1.push(num);}int xn=num/8, yn=num%8;for(j=0; j<8; j++){if(xn+x[j]>=0&&xn+x[j]<=7&&yn+y[j]<=7&&yn+y[j]>=0){if(!exist[(xn+x[j])*8+yn+y[j]]&&!vis[(xn+x[j])*8+yn+y[j]]){if((xn+x[j])*8+yn+y[j]-8>=0&&exist[(xn+x[j])*8+yn+y[j]-8]){continue;}q1.push((xn+x[j])*8+yn+y[j]);vis[(xn+x[j])*8+yn+y[j]]=1;}}}}if(q1.empty()){printf("LOSE");return 0;}for(j=63; j>=0; j--){if(exist[j]){exist[j]=0;if(j<56){exist[j+8]=1;}}}}else{memset(vis, 0, sizeof(vis));while(!q1.empty()){int num=q1.front(); q1.pop();int xn=num/8, yn=num%8;if(num-8<0||!exist[num-8]){q2.push(num);}for(j=0; j<8; j++){if(xn+x[j]>=0&&xn+x[j]<=7&&yn+y[j]<=7&&yn+y[j]>=0){if(!exist[(xn+x[j])*8+yn+y[j]]&&!vis[(xn+x[j])*8+yn+y[j]]){if((xn+x[j])*8+yn+y[j]-8>=0&&exist[(xn+x[j])*8+yn+y[j]-8]){continue;}q2.push((xn+x[j])*8+yn+y[j]);vis[(xn+x[j])*8+yn+y[j]]=1;}}}}if(q2.empty()){printf("LOSE");return 0;}for(j=63; j>=0; j--){if(exist[j]){exist[j]=0;if(j<56){exist[j+8]=1;}}}}}printf("WIN");return 0;
}

codeforces A. Statues相关推荐

  1. Statues CodeForces - 129C(bfs)

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

  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. CodeForces - [ACM-ICPC Jiaozuo Onsite A]Xu Xiake in Henan Province(模拟)

    题目链接:https://codeforces.com/gym/102028/problem/A Time limit: 2.0 s Memory limit: 1024 MB Problem Des ...

  4. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  5. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  8. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  9. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  10. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

最新文章

  1. 计算机网络实验报告建立校园网,计算机网络实验报告
  2. (C++)堆排序的3个关键函数
  3. 鼠标样式(cursor)
  4. IdentityHash as hashMap
  5. 宁波Uber优步司机奖励政策(1月18日~1月24日)
  6. java编程点滴(3)--ubuntu下jdk的配置
  7. Visual Studio 在根目录下运行文件系统站点 [ Visual Studio | 文件系统 | WebDev.WebServer.EXE ]...
  8. leetcode 高薪_利用两种不同的方法解LeetCode第1312题:让字符串成为回文串的最少插入次数
  9. SpringMVC文件上传(一)
  10. 将List按照指定大小等分的几种实现方式和效率对比及优化
  11. Snagit--高难度、多功能截图,有了它截图不求人!
  12. result_of 用法
  13. 2018软科计算机科学工程排行,2018全球计算机与工程学科排名:清华第7,中国9个学科世界第一!...
  14. shell下删除文件末尾的空行
  15. matlab曲线拟合工具箱 cftool
  16. 以下 D 不是MYSQL的对象权限_数据库课后习题及答案
  17. 重庆高考计算机分数线,2017年重庆高考录取分数线
  18. 《引爆核能-销售演讲与呈现技巧》司铭宇
  19. 利用vue实现简单记事本
  20. 什么是审计报告,审计报告有什么类型

热门文章

  1. [学习日志]UI如何与数据绑定?
  2. 基于VC 6.0实现简单的微信打飞机
  3. 解决selenium自动关闭浏览器
  4. 基于Aspect的情感分析
  5. RAR文件格式学习(了解)
  6. Tomcat服务器response header 200 OK问题
  7. 水木周平戏说中国网络黑幽默
  8. Kali系列之网卡地址配置
  9. 网络协议服务器常用默认端口
  10. Git报错--Everything up-to-date branch ‘main‘ set up to track ‘origin/main‘.