BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
2015-07-20 14:24
423 查看
题目传送门
/* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到。因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> using namespace std; const int MAXN = 10; 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 >= 1 && x <= 8 && y >= 1 && y <= 8 && maze[x-s][y] != 'S') return true; return false; } bool BFS(void) { queue<Point> Q; Q.push ((Point) {8, 1, 0}); 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 > 8) return true; if (maze[x-s][y] == 'S') continue; for (int i=-1; i<=1; ++i) { for (int j=-1; j<=1; ++j) { int tx = x + i; int ty = y + j; if (!check (tx, ty, s)) continue; if (!vis[tx][ty][s+1]) { vis[tx][ty][s+1] = true; Q.push ((Point) {tx, ty, s + 1}); } } } } return false; } int main(void) { //Codeforces Beta Round #94 (Div. 2 Only) C. Statues //freopen ("B.in", "r", stdin); n = 8; while (scanf ("%s", maze[1] + 1) == 1) { for (int i=2; i<=n; ++i) { scanf ("%s", maze[i] + 1); } if (BFS ()) puts ("WIN"); else puts ("LOSE"); } return 0; }
相关文章推荐
- 将uiimageview设置成纯圆形
- priority_queue用法
- 动态生成juery-easyui下的折叠面板,在谷歌下格式不正确问题
- UINavigationController与UITabbarController的样式
- POJ 2785 4 Values whose Sum is 0
- iOS中手写UITableViewCell的实现与逻辑(cell固定高度展现)
- Mac OS Create case-sensitive build environment
- ant的安装、使用,build.xml简单编写
- javaGUI猜生日游戏
- Qt数据库:(四)利用QSqlQuery类执行SQL语句(二)
- 从系统UITabbar到自定义UITabbar
- 1051. Pop Sequence (25)
- 1051. Pop Sequence (25)
- JS加载文件规范,AMD,commonJS,requireJs
- UILable
- 【分享】iTOP4412开发板-Bluetooth移植文档
- 【Android】child thread refresh UI
- emulator: ERROR: x86 emulation currently requires hardware acceleration!
- UI开发中的辅助方法
- JAVA常用类之——String和String Builler