POJ 1324(BFS + 状态压缩)

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

思路:

最开始一直没想到应该怎样保存状态,后来发现别人用二进制保存蛇的状态,即每两个节点之间的方向和头节点,二进制最多14位(感觉状态保存都能扯到二进制)。然后就是bfs

问题:

1.最开始完全没想到状态压缩的问题

2.感觉现在做题太急,做题没有足够的思考,思路不清晰便开始写,导致在过程中经常崩盘。



#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
typedef long long ll;
using namespace std;
int flag;
const int maxn = 25;
const int ma = (1<<14)+10;
int vis[maxn][maxn];
int sta[maxn][maxn][ma];
struct node
{
//    int snake[15][2];
    int x,y;
    int step;
    int state;
};
node cur;
int t,n,m;
int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
int matri[20][2];
int get_state()   //蛇的状态
{
    int dir;
    int stat = 0;
    for(int i = t; i > 1; i --)
    {
        int x = matri[i][0]-matri[i-1][0];
        int y = matri[i][1]-matri[i-1][1];
        if(x == -1 && y == 0)
            dir = 0;
        if(x == 0 && y == -1)
            dir = 1;
        if(x == 1 && y == 0)
            dir =2 ;
        if(x == 0 && y == 1)
            dir = 3;
        stat <<= 2;
        stat = stat |dir;
    }
    return stat;
}

bool judge(int x,int y,int x1,int y1,int  state)        //是否吃自己
{
    int s;
    for(int i = 1; i < t; i++)
    {
        s = 3;
        s = state & s;            //取最后两位
        state = state >> 2;
        if(x == x1+dir[s][0] && y == y1+dir[s][1])
            return true;
        x1  = x1 + dir[s][0];
        y1  = y1 + dir[s][1];
    }
    return false ;
}

int get_next(int i,int state)       //去掉高位,输入低位
{
    int x = 0-dir[i][0];
    int y = 0-dir[i][1];
    int dir;

    int k = (1 << ((t - 1) << 1)) - 1;
    if(x == -1 && y == 0)
        dir = 0;
    if(x == 0 && y == -1)
        dir = 1;
    if(x == 1 && y == 0)
        dir =2 ;
    if(x == 0 && y == 1)
        dir = 3;
    state <<= 2;
    state |= dir;
    state = state & k;        //去掉最高位
    return state;
}

void bfs()
{
    queue<node>q;
    cur.step = 0;
    sta[cur.x][cur.y][cur.state] = 1;
    q.push(cur);
    node fo;
    while(!q.empty())
    {
        fo = q.front();
        q.pop();

        for(int i = 0; i < 4; i++)
        {
            int x = fo.x+dir[i][0];
            int y = fo.y+dir[i][1];
            int ts = get_next(i,fo.state);
            if(x < 1 || x > n || y <1 || y > m || vis[x][y] || judge(x,y,fo.x,fo.y,fo.state) || sta[x][y][ts])
                continue;
            if(x == 1 && y == 1)
            {
                printf("%d\n",fo.step+1);
                flag = 1;
                return;
            }
            node tmp;
            tmp.x =x ;
            tmp.y = y;
            tmp.step = fo.step + 1;
//            for(int i = t; i >= 1; i--)
//            {
//                tmp.snake[i][0] = tt.snake[i-1][0];
//                tmp.snake[i][1] = tt.snake[i-1][1];
//            }
            tmp.state = ts;
            sta[x][y][tmp.state] = 1;
            q.push(tmp);
        }
    }
}

int main()
{
    int cas= 1;
    while(scanf("%d%d%d",&n,&m,&t) != EOF)
    {
        memset(vis,0,sizeof(vis));
        memset(sta,0,sizeof(sta));
        if(n == 0 && m == 0 && t == 0)
            break;
        for(int i = 1; i <= t; i++)
            scanf("%d%d",&matri[i][0],&matri[i][1]);

        int a,b,k;
        scanf("%d",&k);
        for(int i = 0; i < k; i++)
        {
            scanf("%d%d",&a,&b);
            vis[a][b] = 1;
        }
        cur.x = matri[1][0];
        cur.y = matri[1][1];
        cur.state = get_state();
        flag = 0;
        printf("Case %d: ",cas++);
        if(cur.x == 1 && cur.y == 1)
        {
            printf("0\n");
            continue;
        }
        bfs();
        if(!flag)
            printf("-1\n");
    }
}





POJ 1324Holedox Moving (状态BFS) Holedox Moving Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15264   Accepted: 3686 Description During winter, the most hungry and severe time, Holedox sle 阅读详情

相关推荐

Arduino四足开源机器猫-Opencat(导航贴)

本内容由我和小伙伴共同编写,未经授权,谢绝转载! 1.项目介绍 2.组装调试教程 (一)Opencat-F (1)资料地址(包含程序代码&&3D打印图纸): 链接:https://pan.baidu.com/s/1AcVA5jSiOSzRKqEQAomrTA 提取码:szfx (2) (二)Opencat-B (1)组装调试 (2)组装调试注意事项 (3)添加新技能 3.编程 ...

qqliuzhitong的博客 4172

POJ 1324 [Holedox Moving] 状态压缩BFS

题目链接:http://poj.org/problem?id=1324 题目大意:n*m网格里有蛇和障碍,蛇只能向空格处移动,不能撞到自己,问到(1,1)的最短步数,如无法到达输出-1. 关键思想:不能直接对蛇头进行BFS,因为蛇身对蛇头的决策也有影响,故BFS时应该保存蛇身状态,我们放在state里用位运算来做。因为根据蛇头和每一节延伸的方向(东南西北)我们可以还原出整条蛇。比较坑的是这道题...

weixin_30363981的博客 203

openlayers6【十九】vue HeatmapLayer热力图层实现热力图效果详解

文章目录1. 写在前面2. Heatmap 类实现热力图2.1 Heatmap 参数2.2 实现热力图3. 完整代码4. 添加删除map图层的方法5. 热力图自身的get,set方法 1. 写在前面 我们主要看热力图的效果,区域绘制效怎么设置详细内容可以访问 openlayers6【十七】vue VectorLayer矢量图层画地图省市区,多省市区(粤港澳大湾区)效果详解 在 openlayers 中,图层是使用 layer 对象表示的,主要有 WebGLPoints Layer、热度图(HeatMap L

@必意玲 1万+

POJ1324(Astar)

题目链接:http://poj.org/problem?id=1324 状态记录:只记录头的位置,其他的部分只要从头部开始沿着连续的方向走就好了,所以只要记录身体与前一段的方向即可。 单纯的BFS也能做,这里作为练习用A*。 先贴A*模板 struct node { type s; int f, g, h; }st,ed; short c[]; int f[]; stru

qust1508060414的博客 776

利用Python实现纬度加权平均(即NCL中的wgt_areaave)

当处理全球数据的时候,最常见的分析就是全球、北半球平均了,这时候一定要注意要根据纬度等信息进行加权,求加权平均,要不然结果肯定会不准。但是对于Python中,常规的计算包里面是没有的,或许现在有其他包可以实现,也可以告诉我~。

记录基于python语言处理气象问题的一些代码,包括不限于气象数据读取、机器学习和深度学习建模。 5745

ROS Motion Planning运动规划库安装方法及进阶使用方法详细介绍

​今天偶然发现了一个优质的运动规划库:ai-winter/ros_motion_planning,比较适合从事ROS移动机器人运动规划研究领域的小伙伴学习和使用,相比于莱斯大学Kavraki实验室提供的开源的著名运动规划库OMPL、或着我之前介绍过的zhm-real开源的zhm-real/MotionPlanning和zhm-real/PathPlanning运动规划库,今天介绍的ROS Motion Planning运动规划库与ROS机器人中常用的Navigation导航框架的兼容性更好,库中的运动规划

慕羽★的博客 5577

POJ1324 Holedox Moving(状态压缩+BFS)

链接:http://poj.org/problem?id=1324 题意,给出蛇的位置和障碍物的位置,求蛇爬到(1,1)的最少步数 一开始在做这题的时候,苦于没办法表示这个蛇的状态,用数组来存一整条蛇的位置,但是这样存很难判断是否访问过这个状态。 看了网上的博客才明白状态压缩的思路。第一次做状态压缩,因为一点小错误找了很久的错。 思路: 用一个结构体来存蛇的状态,3个数据,分

xtttgo的博客 562

Android16 3576 u盘固件升级功能添加

1.在u-boot/drivers/power/pmic/rk8xx.c。这里是读取power键的寄存器判断长短按。

tzj1058756809的博客 575

Holedox Moving----POJ_1324----BFS+状态压缩

题目地址:http://poj.org/problem?id=1324 Holedox Moving Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10948   Accepted: 2602 Description During winter, the most

Bob Lee's Blog For CS 763

NVIDIA - 人形机器人扼要

人形机器人是仿照人类外形设计的通用双足机器人,旨在与人类并肩工作,提高生产效率。它们能够学习和执行各种任务,如抓取物体、移动集装箱、装卸箱子等。

机器人控制与仿真应用 1290

MICCAI‘23 | TSegFormer:基于几何引导Transformer的口内扫描3D牙齿分割

光学口内扫描仪(IOS)在数字牙科中广泛应用于提供牙冠和牙龈的详细3D信息。准确的3D牙齿分割对于各种牙科应用至关重要,但现有方法在复杂边界处容易出错,并且在不同患者之间表现不佳。本文提出了TSegFormer,它通过多任务3D Transformer架构捕捉IOS点云中不同牙齿和牙龈之间的局部和全局依赖关系。此外,作者设计了一种基于新颖点曲率的几何引导损失,以端到端方式优化边界,避免了耗时的后处理,从而实现临床适用的分割。

小白学视觉 291

ACM/ICPC 之 BFS+状态压缩(POJ1324(ZOJ1361))

求一条蛇到(1,1)的最短路长,题目不简单,状态较多,需要考虑状态压缩,ZOJ的数据似乎比POj弱一些 POJ1324(ZOJ1361)-Holedox Moving   题意:一条已知初始状态的蛇,求其到(1,1)的最短路长   题解:开始做的时候用BFS暴力做了一次,结果RE了,后来看了其他的题解和discuss才转向状态压缩。也看到有人用A*做出来了。   ...

disuo8001的博客 209

AI赋能合同审查:构建租赁合同智能审核系统的全流程解析

在商业地产、设备租赁等场景中,合同审核效率直接影响业务流转速度。传统人工审核存在三大痛点:审核周期长(平均2-3个工作日)、合规风险高(条款遗漏率约15%)、人力成本居高不下。智能审核系统可将审核时间压缩至秒级,风险识别准确率提升至98%以上。

理论都是虚的,代码才是王道。 1356

[poj1324]状态压缩+BFS

这题昨天开始做的...因为从来没有做过状态压缩.这是第一次接触.

When you go away 730

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ1324 状态压缩+BFS

很久之前就看到这道题了~~但是困于能力的问题~~~也没想到居然要状压~~~ 蛇头每走一步,相邻的蛇身就会占领前一节蛇头/身所在的位置。因为蛇身只会只有4个方向可以前进,所以我们可以用0、1、2、3代表蛇身的相对前进方向。 这就需要两位二进制。。由于蛇身最多7节,2 int ans[21][21][16400];///ans[i][j][k]:=i,j代表舌头所在地方~~k代表

wishcxz_acm 479

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

状态压缩+BFS POJ - 1324 Holedox Moving

题目大意:一条蛇想吃到在(1, 1)的东西,问最短路径;解题思路:BFS,很经典的问题,但是这个题有一点不同的就是蛇并不是一个点,而是折现,我们所多进行的操作就是判断蛇的下一步移动是否会吃到自己,能吃到就不行。因为蛇长度最长为8,我们可以用状态压缩,保存蛇身体相对于后一节的方向,但事实证明,这个方法不如使用数组存储节点来的简单,状态压缩不是很好想。这里介绍的就是状态压缩做法。利用1&lt;&lt;...

吾之奉先的博客 229

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

poj1324-Holedox Moving-状态压缩+BFS

朴素暴力方法做的。。。 用 一个1 2 3 4表示 当前蛇身与 上一部分蛇身的位置关系,蛇最长为7,所以可以 用 4进制 表示状态,每一个蛇头 ,其蛇身有 4^7种状态 用状态压缩 标记出现过的状态,,以免重复计算TLE。。。。 别的地方就是朴素的BFS。。。。 当然本题还可以用双向bfs,A*算法。。。 以下是朴素方法  :  3.9s... 10520kb #include

缺氧 590

POJ 1324 BFS+状态压缩

Holedox Moving Time Limit:5000MS Memory Limit:65536K Total Submissions:16057 Accepted:3892 Description During winter, the most hungry and severe time, Holedox ...

anuancong1219的博客 214

POJ 1324 贪吃蛇状态压缩BFS

题意  : 给出一个n *m  的地图,地图上有一些石头,蛇不能过去,给你蛇头和蛇身的各个坐标,然后给你石头的坐标 ,问你需要多少步可以将 蛇头移到 1 1 这个点。中间蛇头不可以撞蛇身 ,   游戏规则和普通贪吃蛇一样。 题解 :  裸的广搜,如何标记蛇的状态为关键,蛇头和蛇身之间拥有相对位置关系,mark标记数组   第一二维记录蛇头的坐标,第三维记录蛇关节的相对位置关系,由于蛇长最大为8,

q651111937的专栏 654

poj1324 - Holedox Moving(BFS+状态压缩)

题目链接:点击打开链接 题意: 一只长度为L的蛇要到达左上角的出口,问最短步数。 思路: 在最基本的bfs里,我们要记录每个状态是否已经访问过,在基础题里通常只是一个点,设置一个vis[x][y]=true就ok了。 在这题中,我们要把蛇身整体在某一位置看成一个状态,要表达L长度的身体,需要的空间很大,将是400^8; 我们把蛇头单独抽取出来,作为vis数组的前两维。第

酱油拌面 1430

POJ 1324 Holedox Moving(状态压缩BFS)

题目链接:POJ 1324 Holedox Moving

fobdddf的专栏 2544

POJ-1324(A*+状态压缩)

一开始用deque保存状态信息,用queue进行BFS,TLE

还有多远 1012

poj 1324(BFS+状态压缩)

解题思路:这道题一开始的想法就是状态压缩,即考虑如何判重,由于蛇并非是直线的,所以想到了以每一个点的上下左右共四个 值来表示相对位置。最开始想如何用四进制来表示它,无语。。。。。还是题目做少了,直接用两位来表示一个点即可(两位的二 进制数可以表示0-3)。剩下的关键就是判断蛇头会不会与蛇尾发生碰撞,详细的就看代码吧。。 整体的思路还是比较简单,但是代码很复杂,一般这种复杂点的搜索题代码都挺长

hexianhao的博客 662

POJ 1324 Holedox Moving 贪吃蛇 状态压缩 BFS

Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring comes, Holedox wakes up, moves to the exit of its lair, comes out, and begins its new life. Holedo

旧时光 1309
上一篇: hdu3567 八数码(搜索)--预处理
下一篇: poj2449 (第k条最短路)
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值