zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #94 div 2 C Statues dfs或者bfs

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

    Examples
    input
    .......A
    ........
    ........
    ........
    ........
    ........
    ........
    M.......
    output
    WIN
    input
    .......A
    ........
    ........
    ........
    ........
    ........
    SS......
    M.......
    output
    LOSE
    input
    .......A
    ........
    ........
    ........
    ........
    .S......
    S.......
    MS......
    output
    LOSE

     题意:给你一个8*8的图;每过一秒S下降一格;M可以八个方向加静止不动的走;不能能碰到S。(A有什么用。。。)

     思路:M撑过8秒;

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    #define true ture
    #define false flase
    using namespace std;
    #define ll __int64
    #define inf 0xfffffff
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF )  return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    char a[10][10],ans;
    int check(int x,int y)
    {
        if(x<=0||x>8||y<=0||y>8)
        return 0;
        return 1;
    }
    void dfs(int x,int y,int step)
    {
        if(step>7)
        {
            ans=1;
            return;
        }
        for(int i=-1;i<=1;i++)
        for(int t=-1;t<=1;t++)
        {
            if(ans)
            break;
            int xx=x+i;
            int yy=y+t;
            if(check(xx,yy)&&a[xx-step][yy]!='S'&&a[xx-step-1][yy]!='S')
            dfs(xx,yy,step+1);
        }
    }
    int main()
    {
        int x,y,z,i,t;
        for(i=1;i<=8;i++)
        for(t=1;t<=8;t++)
        cin>>a[i][t];
        dfs(8,1,0);
        if(ans)
        printf("WIN
    ");
        else
        printf("LOSE
    ");
        return 0;
    }
    View Code
  • 相关阅读:
    php 数据库练习之租房子
    php数据访问之查询关键字
    Objective-C代码学习大纲(3)
    Objective-C代码学习大纲(2)
    Objective-C代码学习大纲(1)
    简介Objective-C语言
    为什么Objective-C很难
    Swift之 ? 和 !
    使用Mac App Store更新、下载软件时出现未知错误的解决方法
    如何激励用户为你的app评分?
  • 原文地址:https://www.cnblogs.com/jhz033/p/5455492.html
Copyright © 2011-2022 走看看