Statues CodeForces - 129C(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
.......A
........
........
........
........
........
........
M.......
WIN
.......A
........
........
........
........
........
SS......
M.......
LOSE
.......A
........
........
........
........
.S......
S.......
MS......
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)的更多相关文章
- Amr and Chemistry CodeForces 558C(BFS)
http://codeforces.com/problemset/problem/558/C 分析:将每一个数在给定范围内(10^5)可变成的数(*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 ...
- codeforces #Round354-div2-D(BFS)
题目链接:题目链接 题意:一个n*m的区域,每个格子都有上下左右四个门,相邻的两个格子A可以通向B当且仅当A对B的门和B对A的门都打开,问从起点S到终点T需要的最短时间 #include<bit ...
- Fire Again CodeForces - 35C (BFS)
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows ...
- 深搜(DFS)广搜(BFS)详解
图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...
- 【算法导论】图的广度优先搜索遍历(BFS)
图的存储方法:邻接矩阵.邻接表 例如:有一个图如下所示(该图也作为程序的实例): 则上图用邻接矩阵可以表示为: 用邻接表可以表示如下: 邻接矩阵可以很容易的用二维数组表示,下面主要看看怎样构成邻接表: ...
- 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现
1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...
- 【BZOJ5492】[HNOI2019]校园旅行(bfs)
[HNOI2019]校园旅行(bfs) 题面 洛谷 题解 首先考虑暴力做法怎么做. 把所有可行的二元组全部丢进队列里,每次两个点分别向两侧拓展一个同色点,然后更新可行的情况. 这样子的复杂度是\(O( ...
- 深度优先搜索(DFS)和广度优先搜索(BFS)
深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...
随机推荐
- 047 Permutations II 有重复数字的全排列
给定一个可能包含重复数字的集合,返回所有可能的不同全排列.例如,[1,1,2] 有以下不同全排列:[ [1,1,2], [1,2,1], [2,1,1]] 详见:https://leetcode ...
- java进程占用系统内存高,排查方法
查看所有内存占用情况 top 定位线程问题(通过命令查看16764 进程的线程情况) ps p -L -o pcpu,pmem,pid,tid,time,tname,cmd 计数 ps p -L -o ...
- Kendo UI 单页面应用(四) Layout
Kendo UI 单页面应用(四) Layout Layout 继承自 View,可以用来包含其它的 View 或是 Layout.下面例子使用 Layout 来显示一个 View <div i ...
- ios 开发最新屏幕适配
- win7双网卡走哪个网卡路由设置
有没有软件能做这个我还真不知道.说说我的做法吧: 单位里无线是可以访问Internet的,有线是用来访问公司内部系统的. 默认的54M无线网络和100M的有线网络,系统在选择默认路由的时候肯定是选择有 ...
- Monitorix系统和网络监控工具
Monitorix 系统和网络监控公工具一.monitorixMonitorix是一款功能非常强大的免费开源轻型工具,目的在于监测Linux中的系统和网络资源.它可以定期收集系统和网络数据,并使用自己 ...
- 手工恢复OSSIM数据库密码
1,现象 今天需要远程连接ossim的mysql数据库读取些东西,于是登录ossim的终端,发现这个mysql客户端无法直接登录,使用自己安装时候那些口令都不行 alienvault:~# mysql ...
- LibreOJ #2037. 「SHOI2015」脑洞治疗仪
线段树区间合并问题 恶心... 屠龙宝刀点击就送 #include <cstdio> #define N 200005 struct Segment { int l,r,mid,sum,l ...
- vue validate多表单验证思考 之前写过一个里外层,现在觉得不合适,应该平行的写,然后都给ret,最后判断ret 再做出反应,这样整体表单的所有验证就都报验证,然后最后提交的时候把组件内的对象合并到总的对象,再提交
vue validate多表单验证思考 之前写过一个里外层,现在觉得不合适,应该平行的写,然后都给ret,最后判断ret 再做出反应,这样整体表单的所有验证就都报验证,然后最后提交的时候把组件内的对象 ...
- python之道10
写函数,函数可以支持接收任意数字(位置传参)并将所有数据相加并返回. 答案 def func(*args): count = 0 for i in args: count += i return co ...