CodeForces 128A Statues 简单搜索

题目大意:

现在M从左下角走到右上角

时间 t 时刻可以向周围8个方向没有S的走或者保持原位, 到t + 1是所有S下落一位, 走的途中不能被S重合

问能否走到右上角


大致思路:

很简单的搜索了, dfs或bfs都可以, 没什么难度

我写的dfs...


代码如下:

Result  :  Accepted     Memory  :  12 KB     Time  :  30 ms

/*
 * Author: Gatevin
 * Created Time:  2015/2/14 12:51:44
 * File Name: Mononobe_Mitsuki.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

char maz[10][10];
char now[10][10][8];//now[x][y][t]表示时间t的时候S的时候(x, y)是不是S
int flag;
int dx[] = {1, 1, 1, -1, -1, -1, 0, 0, 0};
int dy[] = {1, 0, -1, 1, 0, -1, 1, -1, 0};

void dfs(int nx, int ny, int t)//dfs向下搜索,当前坐标为(nx, ny)时间为t
{
    if(t >= 8)//8秒依旧存活,一定能安全到右上角
    {
        flag = true;
        return;
    }
    if(nx == 7 && ny == 7)
    {
        flag = true;
        return;
    }
    if(flag) return;
    for(int i = 0; i < 9; i++)
    {
        int tx = nx + dx[i];
        int ty = ny + dy[i];
        if(tx < 8 && tx >= 0 && ty < 8 && ty >= 0 && now[tx][ty][t] != 'S' && now[tx][ty][t + 1] != 'S')
        {
            dfs(tx, ty, t + 1);
        }
    }
    return;
}


int main()
{
    flag = false;
    for(int i = 0; i < 8; i++)
        scanf("%s", maz[i]);
    for(int i = 0; i < 8; i++)
        for(int j = 0; j < 8; j++)
            for(int k = 0; k < 8; k++)
                now[i][j][k] = '.';
    for(int i = 0; i < 8; i++)
        for(int j = 0; j < 8; j++)
            now[i][j][0] = maz[7 - j][i];//我在now中以左下角为(0, 0)
    
    for(int k = 0; k < 8; k++)
        for(int i = 0; i < 8; i++)
            for(int j = 1; j < 8; j++)
                if(now[i][j][k] == 'S')
                    now[i][j - 1][k + 1] = 'S';//做多8次S消失完
    dfs(0, 0, 0);
    if(flag)
        printf("WIN\n");
    else
        printf("LOSE\n");
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值