POJ 1324 Holedox Moving

Name: Holedox Moving
P_ID: POJ 1324
题目链接:http://poj.org/problem?id=1324

题意描述:
n*m(最大20)的迷宫,l长(不超过8)的贪吃蛇,蛇身可弯曲,出口在(1,1),不能走石头所在格子,求蛇身最少移动次数。

题目分析:
题目本身是要考bfs最短路这个很明确,唯一不寻常的是在蛇移动过程中蛇身也在动。刚开始我认为这道题并没有什么特别的地方,于是采用了很普通的一种想法:
正常对头到(1,1)进行bfs,每次状态,我判断头周围的格子,当既不是石头,也不是蛇身的时候,说明这个格子是可以走的,我进行如下三个操作:
1. 蛇身移动一格(依次前移,蛇头新位置入队)
2. 将新的蛇头所在位置vis标记为1
3. 原蛇尾位置标记为空(代表可走)
下面是我的代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 3;

int n, m, l, b;
int num = 0;
char maze[25][25];
int vis[21][21];
const int dir[][2] = {
  {
  0,1}, {
  0,-1}, {
  1,0}, {-1,0}};
struct cell {
    int x;
    int y;
    cell(int a, int b)
    {
        x = a;
        y = b;
    }
};

struct node {
    int x;
    int y;
    int step;
    vector<cell> myBody;
};

int flag = 0;
vector<cell> myBody;


bool check(int x, int y)
{
    if(x<1 || x>n || y<1 || y>m) return false;
    if(maze[x][y]==
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值