BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

题目传送门

 1 /*
 2     BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到。因为雕像最多8步就会全部下落,
 3         只要撑过这个时间就能win,否则lose
 4 */
 5 #include <cstdio>
 6 #include <algorithm>
 7 #include <queue>
 8 #include <vector>
 9 #include <cstring>
10 using namespace std;
11
12 const int MAXN = 10;
13 const int INF = 0x3f3f3f3f;
14 struct Point{
15     int x, y, step;
16 };
17 char maze[MAXN][MAXN];
18 bool vis[MAXN][MAXN][MAXN];
19 int n;
20
21 bool check(int x, int y, int s)    {
22     if (x >= 1 && x <= 8 && y >= 1 && y <= 8 && maze[x-s][y] != ‘S‘)   return true;
23     return false;
24 }
25
26 bool BFS(void)  {
27     queue<Point> Q;   Q.push ((Point) {8, 1, 0});
28     memset (vis, false, sizeof (vis));
29
30     while (!Q.empty ()) {
31         int x = Q.front ().x, y = Q.front ().y, s = Q.front ().step;    Q.pop ();
32
33         if (s > 8)  return true;
34         if (maze[x-s][y] == ‘S‘)    continue;
35
36         for (int i=-1; i<=1; ++i)   {
37             for (int j=-1; j<=1; ++j)   {
38                 int tx = x + i; int ty = y + j;
39                 if (!check (tx, ty, s))    continue;
40                 if (!vis[tx][ty][s+1])  {
41                     vis[tx][ty][s+1] = true;
42                     Q.push ((Point) {tx, ty, s + 1});
43                 }
44             }
45         }
46     }
47
48     return false;
49 }
50
51 int main(void)  {       //Codeforces Beta Round #94 (Div. 2 Only) C. Statues
52     //freopen ("B.in", "r", stdin);
53
54     n = 8;
55     while (scanf ("%s", maze[1] + 1) == 1)  {
56         for (int i=2; i<=n; ++i)    {
57             scanf ("%s", maze[i] + 1);
58         }
59
60         if (BFS ()) puts ("WIN");
61         else    puts ("LOSE");
62     }
63
64     return 0;
65 }
时间: 2024-12-28 17:18:59

BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues的相关文章

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

Codeforces Beta Round #12 (Div 2 Only)

Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7 t

Codeforces Beta Round #29 (Div. 2, Codeforces format)

Codeforces Beta Round #29 (Div. 2, Codeforces format) http://codeforces.com/contest/29 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb p

Codeforces Beta Round #31 (Div. 2, Codeforces format)

Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb p

Codeforces Beta Round #35 (Div. 2)

Codeforces Beta Round #35 (Div. 2) http://codeforces.com/contest/35 A 这场的输入输出是到文件中的,不是标准的输入输出...没注意看,RE了好久... 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x

Codeforces Beta Round #49 (Div. 2)

Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define

Codeforces Beta Round 77 (Div. 2 Only)

layout: post title: Codeforces Beta Round 77 (Div. 2 Only) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 A - Football (签到) 题意 问有没有连续的七个1或者七个0 #include<bits/stdc++.h> using namespace std; typedef long long ll; typ

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform it