BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
2024-08-30 22:08:40
/*
BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到。因为雕像最多8步就会全部下落,
只要撑过这个时间就能win,否则lose
*/
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
struct Point{
int x, y, step;
};
char maze[MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int n; bool check(int x, int y, int s) {
if (x >= && x <= && y >= && y <= && maze[x-s][y] != 'S') return true;
return false;
} bool BFS(void) {
queue<Point> Q; Q.push ((Point) {, , });
memset (vis, false, sizeof (vis)); while (!Q.empty ()) {
int x = Q.front ().x, y = Q.front ().y, s = Q.front ().step; Q.pop (); if (s > ) return true;
if (maze[x-s][y] == 'S') continue; for (int i=-; i<=; ++i) {
for (int j=-; j<=; ++j) {
int tx = x + i; int ty = y + j;
if (!check (tx, ty, s)) continue;
if (!vis[tx][ty][s+]) {
vis[tx][ty][s+] = true;
Q.push ((Point) {tx, ty, s + });
}
}
}
} return false;
} int main(void) { //Codeforces Beta Round #94 (Div. 2 Only) C. Statues
//freopen ("B.in", "r", stdin); n = ;
while (scanf ("%s", maze[] + ) == ) {
for (int i=; i<=n; ++i) {
scanf ("%s", maze[i] + );
} if (BFS ()) puts ("WIN");
else puts ("LOSE");
} return ;
}
最新文章
- Solr4.0 如何配置使用UUID自动生成id值
- http学习笔记(一)
- atitit.ajax bp dwr 3.的注解方式配置使用流程总结 VO9o.....
- activity跳转关闭软件盘
- Linux &; Python 导航目录
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
- Android的WiFi开启与关闭
- 读改善c#代码157个建议:建议10~12
- Android单元测试Junit (一)
- 洗礼灵魂,修炼python(73)--全栈项目实战篇(1)——【转载】前提准备之学习ubuntu
- MYeclipse 和 flex 环境配置
- angularjs学习第一天笔记
- 机器学习中的损失函数 (着重比较:hinge loss vs softmax loss)
- Docker镜像保存save、加载load
- office2016选择性安装
- Ubuntu 14.04 安装 SteamOS 会话
- FE英文缩写
- 【MVC】View与Control之间数据传递
- SpringBoot入门篇--对于JSON数据的返回以及处理二
- angular 程序架构