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

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最短路这个很明确,唯一不寻常的是在蛇移动过程中蛇身也在动。刚开始我认为这道题并没有什么 阅读详情

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. 
Holedox is a special snake, but its body is not very long. Its lair is like a maze and can be imagined as a rectangle with n*m squares. Each square is either a stone or a vacant place, and only vacant places allow Holedox to move in. Using ordered pair of row and column number of the lair, the square of exit located at (1,1). 

Holedox's body, whose length is L, can be represented block by block. And let B1(r1,c1) B2(r2,c2) .. BL(rL,cL) denote its L length body, where Bi is adjacent to Bi+1 in the lair for 1 <= i <=L-1, and B1 is its head, BL is its tail. 

To move in the lair, Holedox chooses an adjacent vacant square of its head, which is neither a stone nor occupied by its body. Then it moves the head into the vacant square, and at the same time, each other block of its body is moved into the square occupied by the corresponding previous block. 

For example, in the Figure 2, at the beginning the body of Holedox can be represented as B1(4,1) B2(4,2) B3(3,2)B4(3,1). During the next step, observing that B1'(5,1) is the only square that the head can be moved into, Holedox moves its head into B1'(5,1), then moves B2 into B1, B3 into B2, and B4 into B3. Thus after one step, the body of Holedox locates in B1(5,1)B2(4,1)B3(4,2) B4(3,2) (see the Figure 3). 

Given the map of the lair and the original location of each block of Holedox's body, your task is to write a program to tell the minimal number of steps that Holedox has to take to move its head to reach the square of exit (1,1). 
Input
The input consists of several test cases. The first line of each case contains three integers n, m (1<=n, m<=20) and L (2<=L<=8), representing the number of rows in the lair, the number of columns in the lair and the body length of Holedox, respectively. The next L lines contain a pair of row and column number each, indicating the original position of each block of Holedox's body, from B1(r1,c1) to BL(rL,cL) orderly, where 1<=ri<=n, and 1<=ci<=m,1<=i<=L. The next line contains an integer K, representing the number of squares of stones in the lair. The following K lines contain a pair of row and column number each, indicating the location of each square of stone. Then a blank line follows to separate the cases. 

The input is terminated by a line with three zeros. 

Note: Bi is always adjacent to Bi+1 (1<=i<=L-1) and exit square (1,1) will never be a stone. 
Output
For each test case output one line containing the test case number followed by the minimal number of steps Holedox has to take. "-1" means no solution for that case.
Sample Input
5 6 4
4 1
4 2
3 2
3 1
3
2 3
3 3
3 4

4 4 4
2 3
1 3
1 4
2 4
4

2 1
2 2
3 4
4 2

0 0 0
Sample Output
Case 1: 9
Case 2: -1
Hint
In the above sample case, the head of Holedox can follows (4,1)->(5,1)->(5,2)->(5,3)->(4,3)->(4,2)->(4,1)->(3,1)->(2,1)->(1,1) to reach the square of exit with minimal number of step, which is nine. 

题意: 输入m,n,l,m行n列,l为蛇身的长度,紧接着l行为 整个蛇的位置,输入p,下面p行为为障碍物的位置;求最少几步在 不撞上蛇身和障碍物时,最少几步到达 (1,1)点,我觉着这题没有说清楚,每走一格,蛇尾也在动,而给你的数据时9步,我觉3步就行了,输出的9步就按9步的写吧;

思路:这道题就是 就是状态不好标记;所以这里用到了 状态压缩, 怎么压缩呢? 从蛇头到蛇身,记录后一个与前一个的相对位置; 因为 4个方向,0,1,2,3, 最大为3,二进制 11,蛇身长度最长为8,所以我们标记最多只需 14位二进制,标记状态就行了,最后两位二进制,表示 蛇身第二个格相于蛇头的位置,倒数3,4 位二进制表示 蛇身第三个相对于 蛇身第二个的位置,依次类推, 在bfs时,可以用 A* 减值,a.step + a.d 表示当前走的步数 加上 到终点的最小步数,最小;

注意提交时,要用G++,c++不过;

有这一道题发现两种 写优先队列的方法,bool operator<(node a) const 这种比较快点;

代码:

  

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

#define Max 21
#include<queue>
int n,m,l;

int mod; 
int a[4][2] = {0,-1,1,0,0,1,-1,0};

int vis[Max][Max][1<<14];
int str[Max][Max];
int sy,sx;
int f1[8],f2[8];
struct node
{
	int x,y;
	int val; // 状态值; 
	int step;
	int d;
	int f1[8];
	int f2[8];
	/*friend bool operator < (node a,node b)  // A*  当前深度 + 到目标的最短的距离; 
	{
		return a.step + a.d > b.step + b.d;
	}*/
	bool operator <(node a) const
	{
		return a.step+a.d < step+d;
	}
};

int fff(int y,int x,int y1,int x1)
{
	if(x>x1)  return 3;
	else if(x<x1) return 1;
	else if(y>y1) return 0;
	else if(y<y1) return 2;
}
int bfs(int k)
{
	node tt;
	tt.x = sx;
	tt.y = sy;
	tt.val = k;
	tt.step = 0;
	for(int i = 0;i<l;i++)
	{
		tt.f1[i] = f1[i]-1;
		tt.f2[i] = f2[i]-1;
	}
	tt.d = sy + sx;
	vis[sy][sx][k] = 1;
	if(sy==0&&sx ==0) return tt.step;
	priority_queue<node >q;
	q.push(tt);
	while(!q.empty())
	{
		node star = q.top();
		q.pop();
		
		for(int i = 0;i<4;i++)
		{
			int tx = star.x + a[i][0];
			int ty = star.y + a[i][1];
			if(tx>=0&&ty>=0&&tx<n&&ty<m&&!str[ty][tx])
			{
				
				node end;
				int p = star.val;
				p = p<<2;
				p %= mod;
				
				int t = fff(ty,tx,star.y,star.x);
				p |= t;
				
				if(!vis[ty][tx][p])
				{
					int j;
					for(j = 0;j<l;j++)
					{
						if(ty==star.f1[j]&&tx==star.f2[j])
							break;
						end.f1[j+1] = star.f1[j];
						end.f2[j+1] = star.f2[j];
					}
					if(j<l) continue;
					end.f1[0] = ty;
					end.f2[0] = tx;
					vis[ty][tx][p] = 1;
					end.x = tx;
					end.y  = ty;
					end.step = star.step + 1;
					end.val = p;
					end.d = ty + tx;
					if(ty==0&&tx==0)
						return end.step;
					q.push(end);
				}				
			}
		}
	}
	return -1;
}

int main()
{
	int i,j;
	int num = 1;
	while(~scanf("%d%d%d",&m,&n,&l)&&(m||n||l))
	{
		scanf("%d%d",&f1[0],&f2[0]);
		memset(vis,0,sizeof(vis));
		memset(str,0,sizeof(str));
		int res = 0;
		 mod = 1<<(2*(l-1));
		for(i = 1;i<l;i++)
		{
			scanf("%d%d",&f1[i],&f2[i]);
			int k = fff(f1[i-1],f2[i-1],f1[i],f2[i]);
			res = res|(k<<(2*(i-1)));
		}
		int k ;
		scanf("%d",&k);
		while(k--)
		{
			int x,y;
			scanf("%d%d",&y,&x);
			str[y-1][x-1] = 1;
		}
		sy = f1[0] - 1;
		sx = f2[0] - 1;
		printf("Case %d: %d\n",num++,bfs(res));
	}
	return 0;
}

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 阅读详情

相关推荐

北大POJ 1324.cpp

北大POJ第1324题(C++)

POJ 1324 [Holedox Moving] 状态压缩BFS

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

weixin_30363981的博客 203

别再手动算频谱了!用这个在线FFT工具,5分钟搞定JSON/CSV数据分析

本文介绍了一款高效的在线FFT工具,帮助用户快速分析JSON/CSV格式的时域数据,5分钟内完成频谱分析。通过傅里叶变换(FFT)算法,大幅提升计算效率,解决传统手动计算的痛点,适用于工业振动分析、设备故障诊断等场景。

weixin_29172201的博客 279

POJ-1324 Holedox Moving

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. Hol...

weixin_30496431的博客 188

[苹果开发者账号]03 申请APPID、苹果开发者账号 常见问题整理

目录:问题持续更新问题一:提示:抱歉,您暂时不能注册问题二:Apple Developer Support提示:联系我们以继续流程 问题一:提示:抱歉,您暂时不能注册 申请苹果开发者账号,应该先注册AppleID,由于很多都是申请的公司使用的苹果开发者账号。一般操作申请动作的人,可能是新手操作,也可能图方便,有些信息会随便填写。 有些人会把姓名填写为,公司的产品、简称、缩写等等。这是不对的。 还有出生日期也会随便乱填。生日如果填写的不对,会被苹果限制使用一些功能的(苹果给的提示不是太明确)。 当生日填写的

专注于技术开发、项目管理 1万+

绝对旋转编码器学习笔记(基本原理,与PC通信等,不定期更新中)

前言 最近开始学习编码器相关内容,目的在于搞清楚编码器的原理,与上位机的联系等问题。笔记资料来源为网络,整理的同时也会有一些总结和感悟。由于研究方向需求,主要研究数字旋转编码器。 1.编码器的定义 编码器(encoder)是将信号(如比特流)或数据进行编制、转换为可用以通讯、传输和存储的信号形式的设备。——摘自《百度百科》 通常来说,编码器可以将角度位移、直线位移、转速等物理量转换为电信号。这里的电信号根据不同原理的编码器输出脉冲、二进制数码等不同的类型,下面会提到。 2.编码器的分类 编.

黑化咸鱼的博客 1万+

POJ 1324 Holedox Moving 搜索

题目地址: http://poj.org/problem?id=1324 优先队列---A*的估价函数不能为蛇头到(1,1)的距离,这样会出错。 超时代码: #include #include #include #include #include #include #include #include #include #include #include

lamborghini1993 1130

uniapp:实现扫描二维码+自定义扫描框+扫一扫功能,支持扫码识别二维码、条形码(条码)、微信/支付宝等二维码功能,自定义扫码页面可添加按钮或文字展示布局(移动端H5网页/小程序/安卓苹果APP端)

UNI-APP实现扫描二维码,uniapp扫描条形码,uniapp实现扫一扫功能,扫码成功后跳转页面,uniApp扫描条码,uniApp-H5 使用摄像头扫码功能(扫一扫),实现手机扫描二维码并跳转全过程示例代码,用户扫码后自动跳转到链接,uniapp怎么调用扫一扫功能,uniapp实现扫一扫功能,uniapp请求相机使用权限,扫一扫权限申请,uniapp调用摄像头扫码,uniapp实现调用相机扫码,UniApp 实现扫描二维码,uniapp APP安卓苹果ios实现扫码扫一扫,Uniapp微信小程序扫描二

✅ 精选推荐文章 4768

poj 1324 Holedox Moving

poj 1324Holedox Moving 题目地址:http://poj.org/problem?id=1324 题意: 给出一个矩阵中,一条贪吃蛇,占据L长度的格子, 另外有些格子是石头, 不能通过, 请问蛇到达 (1,1)格子最短距离。 明显的BFS问题, 将每一个可以走的格子进入队列, 格子判断能否走?(给蛇身体标序号(蛇头l, 蛇尾1,其他置为0)...

weixin_30679823的博客 154

SAP Joule 经过了超过 2.5 亿行 ABAP 代码的训练之后......

披露的统计数据,Joule 提供的这种全新系统交互方式,可将事务性任务执行速度提高 90%,访问 SAP Help Portal 内容的速度提高 95%。在 ABAP 应用开发领域,SAP 官网数据显示,Joule 经过超过 2.5 亿行 ABAP 代码的训练,有信心成为这一领域行业领先的代码助手。刚刚过去的 SAP 蓝宝石大会上,SAP 提到,从2023年第四季度以来,SAP 已经交付了 50 项基于人工智能的创新。让其生成 SAP 应用能够识别的结构化应用数据,业务用户全程无需离开 SAP 应用程序。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 825

10、现代统计方法:趋势面分析、薄板样条与广义线性模型

本文系统介绍了空间预测建模中的三种现代统计方法:趋势面分析(TSA)、薄板样条(TPS)和广义线性模型(GLM)。详细阐述了每种方法的原理、实现步骤、参数优化与预测评估,并结合R语言代码示例展示了在实际数据中的应用。文章还提供了方法对比流程图与土壤湿度预测案例,帮助读者根据数据特征选择合适模型,提升空间预测的准确性与可靠性。

play7的博客 168

POJ - 1324 Holedox Moving (状态压缩+BFS/A*)

题目链接 有一个n*m(1<=n,m<=20)的网格图,图中有k堵墙和有一条长度为L(L<=8)的蛇,蛇在移动的过程中不能碰到自己的身体。求蛇移动到点(1,1)所需的最小步数。 显然用8个(x,y)来表示蛇的状态是不现实的(用哈希也很难存下,要么爆内存,要么超时),所以首先应当进行状态压缩。可以发现蛇的身体是连续的,因此可以用一个表示方向的向量来储存蛇身体的每个部分在它上个部...

weixin_30838921的博客 183

R语言 Chow Test

Chow 测试用于测试不同数据集上的两个不同回归模型中的系数是否相等。 该测试通常用于计量经济学领域,使用时间序列数据来确定数据在某个时间点是否存在结构性中断。 本教程提供了如何在 R 中执行 Chow 测试的分步示例 首先,我们将创建一些假数据: #create data data <- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 10, 10, 11, 12, 12, 13,

Mrrunsen的博客 1952

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 766

踩坑2周总结:Python+YOLO26搭建工业级多路视频分析应用,从单路卡顿到16路4K稳跑30FPS

本文分享了工业级多路视频分析系统的实战经验,针对智慧物流园区的车辆违停和人员安全监测需求,提出了一套完整的解决方案。作者通过踩坑实践,总结出多路视频分析的四大核心痛点:视频流解码瓶颈、推理调度混乱、内存占用爆炸和部署兼容性差。 文章详细介绍了技术选型方案,推荐使用FFmpeg+PyAV进行硬件加速解码、YOLO26+TensorRT INT8量化推理、单进程多线程的生产者-消费者架构,以及内存池复用等技术组合。该方案在RTX 4070 Ti上实现了16路4K视频30FPS稳定运行,GPU利用率达85%以上,

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 964

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

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

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

酱油拌面 1432

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

POJ 1324 Holedox Moving 贪食蛇

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.  Hol

just_water 2412

深度学习工具包 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")

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

poj1324-Holedox Moving-状态压缩+BFS

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

缺氧 591

状态压缩+BFS POJ - 1324 Holedox Moving

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

吾之奉先的博客 229

POJ1324 Holedox Moving(状态压缩+BFS)

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

xtttgo的博客 563

poj 1324 Holedox Moving (贪吃蛇 状态压缩存蛇的状态)

Holedox Moving Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12014   Accepted: 2882 Description During winter, the most hungry and severe time, Holedox sle

To be what you what to be! 1067

Holedox Moving POJ - 1324

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. Holedox is a special...

sinker 317

POJ 1324 Holedox Moving(图论:BFS)

POJ 1324 Holedox Moving(图论:BFS) http://poj.org/problem?id=1324 题意:有一个迷宫,问你一条蛇最少多少步能走到出口(1,1)。 分析: 直接BFS,不过这里的vis状态表示要注意。由于蛇最长为8格。所以我们用vis[21][21][1 这样我们就能用最小的空间表示完整个蛇在迷宫的状态了. 现在要求最小距离,我们不用dist[]

code 2054

POJ 1324 Holedox Moving(状态压缩BFS)

题目链接:POJ 1324 Holedox Moving

fobdddf的专栏 2545

poj 1324 Holedox Moving(BFS+位运算状压判重)

Holedox Moving Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12871   Accepted: 3040 Description During winter, the most hungry and severe time, Holedox sle

u014458169的专栏 630
上一篇: Master of GCD HDU - 6273 (区间更新,线段树)
下一篇: 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 Goldbach(2^63 次方内的素数判断,Miller-Rabin素数检测算法)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址