zoukankan      html  css  js  c++  java
  • Statues CodeForces

    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

    Input
    .......A
    ........
    ........
    ........
    ........
    ........
    ........
    M.......
    Output
    WIN
    Input
    .......A
    ........
    ........
    ........
    ........
    ........
    SS......
    M.......
    Output
    LOSE
    Input
    .......A
    ........
    ........
    ........
    ........
    .S......
    S.......
    MS......
    Output
    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=505;
    const int mod=1e9+7;
    
    
    char mat[10][10];
    bool vis[10][10];
    bool dang[10][10][100];
    
    bool ok(int x, int y, int t)
    {
        if (x < 0 || x > 7 || y < 0 || y > 7 || dang[x][y][t] || vis[x][y])
        {
            return 0;
        }
        return 1;
    }
    
    bool dfs(int x, int y, int t)
    {
        if (dang[x][y][t])
        {
            return 0;
        }
        if (x == 0 && y == 7)
        {
            return 1;
        }
        for (int dx = -1; dx <= 1; dx++)
        {
            for(int dy=-1;dy<=1;dy++)
            {
            int xx = x + dx;
            int yy = y + dy;
            if (!ok(xx, yy, t))
            {
                continue;
            }
            vis[xx][yy] = 1;
            if (dfs(xx, yy, t + 1))
            {
                return 1;
            }
            vis[xx][yy] = 0;
            }
        }
        if (t <=9)
        {
            if (dfs(x, y, t + 1))
            {
                return 1;
            }
        }
        return 0;
    }
    
    int main()
    {
        while (~scanf("%s", mat[0]))
        {
            for (int i = 1; i < 8; ++i)
            {
                scanf("%s", mat[i]);
            }
            memset(dang, 0, sizeof(dang));
            for (int i = 0; i < 8; ++i)
            {
                for (int j = 0; j < 8; ++j)
                {
                    if (mat[i][j] == 'S')
                    {
                        dang[i][j][0] = 1;
                        int k = i + 1, t = 1;
                        while (k < 8)
                        {
                            dang[k++][j][t++] = 1;
                        }
                    }
                }
            }
            memset(vis, 0, sizeof(vis));
            vis[7][0] = 1;
            if (dfs(7, 0, 0))
            {
                printf("WIN
    ");
            }
            else
            {
                printf("LOSE
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    vim技巧2
    vim技巧1
    网站压力测试工具
    CentOS mysql安装
    破解root
    渐进式性能监测案例
    网络监测介绍
    I/O检测介绍
    虚拟内存介绍
    @Slf4j
  • 原文地址:https://www.cnblogs.com/smallhester/p/9500346.html
Copyright © 2011-2022 走看看