题目大意:
现在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;
}