现在的位置: 首页 > 综合 > 正文

CodeForces 128A

2013年05月19日 ⁄ 综合 ⁄ 共 3022字 ⁄ 字号 评论关闭
A. Statues
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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".

Sample test(s)
input
.......A
........
........
........
........
........
........
M.......
output
WIN
input
.......A
........
........
........
........
........
SS......
M.......
output
LOSE
input
.......A
........
........
........
........
.S......
S.......
MS......
output
LOSE

分析:

搜索,BFS或是DFS,这里是用BFS写的。需要预先将每一秒所有雕像的位置都算清楚,以便与M判断是否相遇。

代码如下:

#include <cstdio>
#include <cstring>
struct point
{
    int x, y;
} que[3000000];
int sta_x[]= {1,1,1,-1,-1,-1,0,0,0};
int sta_y[]= {-1,0,1,-1,0,1,-1,1,0};
char a[10][10];
void Move()//移动雕像
{
    for(int i=7; i>=0; i--)
        for(int j=0; j<8; j++)
            if(a[i][j]=='S')
            {
                a[i+1][j]='S';
                a[i][j]='.';
            }
}
bool bfs()
{
    int font = 0, rear = 1, po=0;
    que[font].x = 7;
    que[font].y = 0;
    while(font<rear)
    {
        for(int i=0; i<9; i++)
            if(que[font].x+sta_x[i]>=0
             &&que[font].x+sta_x[i]<8
             &&que[font].y+sta_y[i]>=0
             &&que[font].y+sta_y[i]<8)
            {
                int xx = que[font].x+sta_x[i];
                int yy = que[font].y+sta_y[i];
                if(xx-1>=0 && a[xx-1][yy]=='S')
                    continue;
                if(a[xx][yy]=='S')
                    continue;
                if(xx==0 && yy==7)
                    return true;
                que[rear].x = xx;
                que[rear].y = yy;
                ++rear;
            }
        if(font>=po)// 每次步数加一时,所有石头往下掉一格
        {
            Move();
            po = rear;
        }
        ++font;
    }
    return false;
}
int main()
{
    while(scanf("%s", a[0]) != EOF)
    {
        for(int i=1; i<8; i++)
            scanf("%s", a[i]);
        if(bfs())
            puts("WIN");
        else
            puts("LOSE");
    }
    return 0;
}

抱歉!评论已关闭.