POJ 2312 Battle City 优先队列+BFS

java版坦克大战源码-battle-city-ai:战斗城市-ai java版坦克战争源码战斗城市-ai 传奇 这是什么? 它是 NES 战斗城市的简单克隆。 视频: 这是如何运作的? 游戏在带有游戏窗口的服务器上运行,并侦听两个连接:player1 和 player2。 每个玩家都是一个单独的客户端(坦克)连接到游戏服务器。 客户端通过向服务器发送动作来控制他们的坦克。 当两个连接都建立并且问候消息发送到两个客户端时,游戏就开始了。 客户端的动作被定义一次,并且在游戏过程中不会发生任何变化。 目标是什么? 有两个目标: 在 2 分钟内生存 获得比第二名玩家更多的积分 如何做到这一点? 为了生存并获得最多的分数,您需要以彻底而聪明的方法来规划客户的动作。 尖端 去做 分数 1对于每个破坏微小砖 每个“冻结”第二个玩家5个 每个被摧毁的 NPC 坦克200 每枚硬币100 协议文档 是 。 如何安装? 克隆这个 repo。 代码适用于 Python 3.5、3.6 和 3.7 记住virtualenv 或 pipenv ! 如果您不是 Pythonic 程序员,那么我为您准备了备忘单: 创建: virtualenv -ppython3 venv 设置虚拟 立即下载

      相信坦克大战大家都玩过吧,本题就是根据这个游戏设计的。坦克要从起点(Y),到目的地(T),坦克不能通过钢墙(S),河(R),可以在空地在行走(E),射击破坏砖墙(B),射击砖墙时不行走且花费一个单位的时间,在空地上行走时也花费一个单位的时间。求坦克从起点到目的地最少花多少时间,不可达输出-1;
     很好的一道搜索题。因为考虑到通过砖墙时和空地所花的时间不同,所以不能使用一般的BFS广搜来做。用DFS深搜,你会发现时间复杂非常高,必然会超时(最大是300*300的图)。本题可以使用改进过的广搜或优先队列+bfs 或 记忆化广搜三种方法来解决。

第一种方法:改进过的BFS:

有些节点需要耗费2个单位时间,要想用BFS就得改一下,由于BFS每次只能操作一步,要不就是扩展,要不就是破坏砖墙。所以只需检查该点是不是'B',是的话就得停一步,不是的话,继续扩展,也就是说某些点的扩展慢了一拍,所以从队列里出来的点就判断一下再看执行哪个操作。

从这道题,我也对bfs有了更深的理解,“bfs之所以能最快找到最优解,就是因为它每次操作一步(这里的操作一步,很灵活,例如题目中的破坏砖墙),而while()里面的语句就是一次操作了!”

/*
这道题中B点需要操作两步,所以遇到B点后不能+2后直接压进队列,需要在原地停一下,不能扩展到其他点,相当于他只能扩展到自身,所以就把自身压进队列里map[x][y]='E'是因为破坏砖墙一次就够了,不然下次,还是'B',不断压进队列,不断在原地停留
平常一般是考虑“入队列” 的点,这次要考虑“出队列” 的点是否满足条件!
*/
#include "iostream"
#include "queue"
using namespace std;

char map[301][301];
bool visit[301][301];
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int m,n,sx,sy;

struct node
{
	int x,y,time;
};
int bfs()
{
	int i;
	node you,start,next;
	queue<node>q;
	you.x=sx;
	you.y=sy;
	you.time=0;

	q.push(you);
	visit[sx][sy]=1;

	while(!q.empty())
	{
		start=q.front();
		q.pop();
		if(map[start.x][start.y]=='B')  //这一步需要停一停
		{
			start.time++;
			map[start.x][start.y]='E';
			q.push(start);
		}
		else
		{
			for(i=0;i<4;i++)
			{
				next.x=start.x+dir[i][0];     //搜索下一个点
				next.y=start.y+dir[i][1];
				if(next.x<0 || next.y<0 || next.x>=m || next.y>=n || map[next.x][next.y]=='R' || map[next.x][next.y]=='S' || visit[next.x][next.y])        //判断下一个点是否合法
					continue;
				next.time=start.time+1;

				if(map[next.x][next.y]=='T')    //到达目的地
					return next.time;
				visit[next.x][next.y]=1;   //标记已经走过的点
				q.push(next);
			}
		}
	}
	return -1;
}
int main(void)
{
	int i,j;
	while(scanf("%d %d",&m,&n)==2)
	{
		if(m==0 && n==0)
			break;
		memset(visit,0,sizeof(visit));     //初始化每个节点的状态
		for(i=0;i<m;i++)
		{
			getchar();
			for(j=0;j<n;j++)
			{
				scanf("%c",&map[i][j]);
				if(map[i][j]=='Y')      //记录起始点
				{
					sx=i;
					sy=j;
				}
			}
		}
		printf("%d\n",bfs());
	}
	system("pause");
	return 0;
}

第二种方法:优先队列+BFS法
     也是用到了广搜的思想,只是在出队时做了处理,利用优先队列让队列中到起点的时间值最小的点先出队。该方法会用到优先队列的STL。

首先需要了解优先队列的使用规则:

优先队列中元素的比较规则默认是按元素的值从大到小排序的,就是说队列中最大的元素总是位于队首,所以出队时,并非按先进先出的原则进行,而是将当前队列中最大的元素出队。这点类似于给队列里的元素进行了从大到小的排序。当然,可以通过重载“<”操作符来重新定义比较规则。

重载“<”操作符的函数可以写在结构体里面,也可以写在结构体外面,写在结构体外面的时候,记得函数的参数要使用引用。。

第一种重载方法:

struct node
{
	int x,y;
	int step;
};
priority_queue<node>q;       //优先队列中元素的比较规则默认是按元素的值从大到小排序;

bool operator<(const node &a,const node &b) //括号里面是const 而且还必须是引用
{
	return a.step>b.step;          //从小到大排序。重载小于号。因为默认是从大到小
}

第二种重载方法:

struct node
{
	int x,y;
	int time;  //定义一个优先队列
	friend bool operator<(node a, node b)
	{     //从小到大排序采用“>”号;如果要从大到小排序,则采用“<”号
		return a.time> b.time;       //从小到大排序
	}
};  
priority_queue<node>q;       //优先队列中元素的比较规则默认是按元素的值从大到小排序;

切记:从小到大排序采用“>”号;如果要从大到小排序,则采用“<”号;

/*
优先队列的实现就不用局限每次操作一步了,但每次都取最小操作次数的步来走
*/
#include "iostream"
#include "queue"
using namespace std;

char map[301][301];
bool visit[301][301];
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int m,n,sx,sy;

struct node
{
	int x,y,time;  //定义一个优先队列
	friend bool operator<(node a, node b)
	{
		return a.time> b.time;       //从小到大排序
	}
};
int bfs()
{
	int i;
	node you,start,next;
	priority_queue<node>q;
	you.x=sx;
	you.y=sy;
	you.time=0;

	q.push(you);
	visit[sx][sy]=1;

	while(!q.empty())
	{
		start=q.top();  //取队头指针与普通队列不同(Q.front)
		q.pop();
		for(i=0;i<4;i++)
		{
			next.x=start.x+dir[i][0];     //搜索下一个点
			next.y=start.y+dir[i][1];
			if(next.x<0 || next.y<0 || next.x>=m || next.y>=n || map[next.x][next.y]=='R' || map[next.x][next.y]=='S' || visit[next.x][next.y])        //判断下一个点是否合法
				continue;
			if(map[next.x][next.y]=='B')  //注意此处不要马虎
				next.time=start.time+2;
			else
				next.time=start.time+1;

			if(map[next.x][next.y]=='T')    //到达目的地
				return next.time;
			visit[next.x][next.y]=1;        //标记已经走过的点
			q.push(next);
		}
	}
	return -1;
}
int main(void)
{
	int i,j;
	while(scanf("%d %d",&m,&n)==2)
	{
		if(m==0 && n==0)
			break;
		memset(visit,0,sizeof(visit));     //初始化每个节点的状态
		for(i=0;i<m;i++)
		{
			getchar();
			for(j=0;j<n;j++)
			{
				scanf("%c",&map[i][j]);
				if(map[i][j]=='Y')      //记录起始点
				{
					sx=i;
					sy=j;
				}
			}
		}
		printf("%d\n",bfs());
	}
	system("pause");
	return 0;
}

第三种方法:记忆化广搜
     和优先队列BFS在出队时做处理不同的是,记忆化广搜是在点入队是做处理。记忆化广搜时不必要对点进行标记,只是在入队是注意选择。比如若搜到A点时,要选择比A点时间值大的邻接点入队(不能相等),并更新入队点的时间值。

#include<string.h>
#include<iostream>
#include<queue>
using namespace std;

int co,ro,mi,step[305][305];
char map[305][305],visited[305][305];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
typedef struct node
{
	int x;
	int y;
	int time;
}node;
bool judge(int x,int y)
{
	if(x<0||y<0||x>=co||y>=ro)
	{
		return false;
	}
	if(map[x][y]=='S'||map[x][y]=='R')
	{

		return false;
	}

	return true;
}
void  bfs(int a,int b)
{
	int i,x,y,ti;
	node in,out;
	queue<node>que;
	in.x=a;
	in.y=b;
	step[a][b]=0;
	que.push(in);
	while(!que.empty())
	{
		out=que.front();
		que.pop();
		visited[out.x][out.y]=0;   
		for(i=0;i<4;i++)
		{
			x=out.x+dir[i][0];
			y=out.y+dir[i][1];
			if(!judge(x,y))
				continue;
			ti=step[out.x][out.y]+1;
			if(map[x][y]=='B')
				ti++;
			if(step[x][y]<=ti)
				continue;
			step[x][y]=ti;
			if(visited[x][y])
				continue;
			visited[x][y]=1;
			in.x=x;
			in.y=y;
			que.push(in);
		}
	}
}

int main()
{
	int i,j,a,b,c,d;
	while(scanf("%d %d",&co,&ro),co+ro)
	{
		getchar();
		for(i=0;i<co;i++)
			gets(map[i]);
		for(i=0;i<co;i++)
			for(j=0;j<ro;j++)
			{
				if(map[i][j]=='Y')
				{
					a=i;
					b=j;
				}
				if(map[i][j]=='T')
				{
					c=i;
					d=j;
				}
				step[i][j]=999999;       
			}

			memset(visited,0,sizeof(visited));
			visited[a][b]=1;
			bfs(a,b);
			if(step[c][d]!=999999)
				printf("%d\n",step[c][d]);
			else
				printf("-1\n");
	}
	return 0;
}


【Apollo规划模块探秘】—— 场景(Scenario)驱动的决策引擎 本文深入解析了Apollo自动驾驶平台规划模块的核心机制——场景(Scenario)驱动的决策引擎。文章通过类比日常驾驶,阐述了规划模块如何像经验丰富的司机一样,根据不同的路况(如车道跟随、无保护左转)切换不同的“驾驶模式”。重点剖析了场景管理器(ScenarioManager)如何基于感知信息进行场景判断与切换,以及“场景-阶段-任务”双层状态机如何精密协作,实现灵活、高效且安全的轨迹规划。 阅读详情

相关推荐

iSLIP算法实战:如何用Python模拟交换机优先级匹配(附完整代码)

本文详细介绍了如何使用Python实现iSLIP算法,模拟交换机优先级匹配过程。通过核心的指针滑动逻辑和迭代循环策略,构建了一个完整的iSLIP算法模拟器,并加入可视化模块以直观展示匹配过程。文章还提供了完整的代码框架和性能优化建议,适合网络工程师和Python开发者直接集成到测试环境中。

weixin_29313239的博客 249

Battle City(POJ 2312)

<br />问题描述 <br />许多人都玩过坦克大战这个游戏,我们现在来考虑一下这个游戏的简化版本: 给出一个地图,这个地图上只有空地,河流,金属墙和砖墙,你的目标是从你当前的位置尽快地获得Bonus(不考虑敌人),如下图: <br /> <br />你的坦克不能穿过河流和墙,但是它可以开炮摧毁砖墙.如果你打中砖墙的话,那个位置就会变成空地.如果你击中了金属墙面,你不会对它造成任何损坏. <br />在你行动的每一步,你可以选择移动,或者是不移动而向某个方向开炮,炮弹会向前直行直到击中某一面墙或者飞出地图

Augmented Reality & Computer Graphics 1851

TI DSP TMS320F280025 Note1:工程模板Template创建

该方法新建的工程支持寄存器开发,同时也支持库函数开发,新建后移动该工程也不需要重新修改路径,路径使用变量定义,使用方便、移植性能高

weixin_52849254的博客 2302

【BFS+优先队列】Battle City(poj-2312)

原题链接点击打开链接 其实现在仔细想想,对初学者而言,在BFS和DFS中,还真是BFS学起来更为容易(至少我是这么认为)。BFS不需要层层递归,不需要考虑搜索路径不符合条件时应该如何变换。它只是一步一步的扫描,然后把相关信息归纳一下而已。我们需要的知识少许的STL知识就行了。 言归正传,这道题应该属于迷宫搜索题,而在搜索过程中,又要找出最少“消耗”的那一条路,从这点看,又有点像图论中的最短路了

Mr.ProphetK 690

VSCode配置C/C++开发环境:从零安装MinGW-w64并运行第一个C程序

在Windows系统上搭建C语言开发环境时,很多初学者混淆编辑器、编译器与调试器的分工,导致配置过程屡屡受挫。理解VSCode作为轻量级编辑器的定位,以及MinGW-w64提供的gcc编译器在源码编译中的核心作用,是顺利完成环境配置的关键。环境变量的正确设置直接影响gcc命令能否全局调用,而C/C++插件则赋予编辑器语法高亮与智能提示能力。通过安装VSCode、配置MinGW-w64、安装插件、汉化界面并运行一个最简单的hello.c程序,就能系统掌握这套开源工具链的完整工作流。无论是用于课程学习、算法练习

weixin_42531923的博客 531

解决 TensorFlow 和 Keras 的 Python 版本兼容问题:详细技术指南

本文提供了TensorFlow和Keras与Python版本不兼容问题的完整解决方案。通过版本对照表指出不同TensorFlow版本对应的Python支持范围,强调2.13.x仅支持Python 3.9-3.11,且不兼容Python 3.12+。给出最佳实践建议:使用虚拟环境管理项目依赖,推荐venv或conda创建独立环境;指导正确安装TensorFlow和Keras版本,建议优先使用tf.keras避免冲突;针对常见报错如DLL加载失败、模块导入错误等提供具体解决方法。最后给出一个在兼容环境中运行的M

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

广度优先搜索BFS进阶(一):多源BFS、优先队列BFS、双端队列BFS

普通队列BFS:适用于无权图;双端队列BFS:适用于边权为0或1且到每个顶点的边权都相等的带权图;优先队列BFS:适用于边权不为负且到每个顶点的边权都相等的带权图;如果图上到每个顶点的边权不等,则需使用最短路算法。

yuhaomogui的博客 2487

AE-扭曲-变形-弧

一些AE效果的着色器实现记录

What_can_you_do的博客 1173

【POJ】2312-Battle City (bfs,优先队列)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7805   Accepted: 2613 Description Many of us had played the game "Battle city" in our childhood

wyg1997 1070

基于STM32L4XX、HAL库的 L76KB-A58定位模块驱动程序设计

/ 确保字符串终止。// 缓冲区溢出,重置。// 重置缓冲区索引。支持GPS、GLONASS、Galileo、北斗和QZSS多系统定位。case 1: // UTC时间。// 配置GPS模块(可选)// 查找GGA语句。// 启动UART接收。// USART1初始化函数。内置LNA和SAW滤波器。

zhusl6688的博客 349

【首发独家】华为OD机试 - 服务中心选址、服务中心的最佳位置(C 语言解题)

最近更新的博客 华为 od 2023 | 什么是华为 od,od 薪资待遇,od 机试题清单 华为 OD 机试真题大全,用 Python 解华为机试题 | 机试宝典 【华为 OD 机试】全流程解析+经验分享,题型分享,防作弊指南 华为 od 机试,独家整理 已参加机试人员的实战技巧 本篇华为 OD 机试题解:服务中心选址、服务中心的最佳位置

梦想橡皮擦,专栏100例写作模式先行者,现象级专栏 《Python 爬虫 100 例》作者、《滚雪球学 Python 专栏》原创者 1万+

POJ 2312 Battle City(优先队列+BFS)

题目链接:http://poj.org/problem?id=2312 Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7085   Accepted: 2390 Description Many of us had playe

MummyDing's Blog 2491

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

poj 2312 Battle City(优先队列+bfs)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7897   Accepted: 2640 Description Many of us had played the game "Battle city" in our childhood,

Calm微笑 517

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

bfs解决poj 2312 battle city(优先队列)

Battle City 题目链接 题目描述 简单描述一下,细节点击题目链接进行查看。 给定m,n,然后给定m*n的矩阵,矩阵元素由 ‘Y’ (you), ‘T’ (target), ‘S’ (steel wall), ‘B’ (brick wall), ‘R’ (river) and ‘E’ (empty space)中的几个元素组成,并且’Y’和’T’只出现一次,现要求从Y尽快走到T。 其中B表示的位置必须要射击一次,再走一步才算到达,E表示的位置可走一步直接到达,S和R表示的位置不可通过。 解题思路 要

weixin_43966538的博客 393

【bfs+优先队列】POJ2312-Battle City

【思路】 题目中的“可以沿直线发射打破砖墙”可能会迷惑到很多人,实际上可以等价理解为“通过砖墙的时间为2个单位”,这样题目就迎刃而解了。第一次碰到时可能不能很好把握,第二次基本就可以当作水题了。 【错误点】 1.不能用裸的bfs。广搜的实际思想是将到达时间最短的放在队首,这样首次到达终点即为时间的最小值。通过砖墙的时间为两个单位,通过砖墙后可能不是时间最小值。用优先队列可以解决这一...

dianchunhui2654的博客 153

POJ 2312 Battle City(优先队列+bfs)

Problem Description Many of us had played the game "Battle city" in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this g...

wcxyky的博客 266

POJ2312 Battle City(BFS+优先队列)

题目链接 题意: 输入M×N大小的地图,其中’Y’表示起点,'T’表示终点,'S’与’R’表示不可以通过的障碍,'E’表示可以通过,'B’表示可以拆除的障碍,求解从起点到终点的最短路径。 思路: 本题中可以扩展的结点分为两类: (1)‘E’:通过需一个时间单位 (2)‘B’:通过需两个时间单位 利用优先队列,优先扩展用时最少的结点,其余操作与基础广搜相同。 代码实现: #inclu...

Keep eating codes! 307

poj2312 Battle City 【暴力 或 优先队列+BFS 或 BFS】

题意:M行N列的矩阵。Y:起点,T:终点。S、R不能走,走B花费2,走E花费1.求Y到T的最短时间。 三种解法。♪(^∇^*) //解法一:暴力 //157MS #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #incl...

dhe56357的博客 109

poj 2312 Battle City bfs +优先队列

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6496   Accepted: 2176 Description Many of us had played the game "Battle city" in our childhood,

小磊's blog 883

POJ 2312 Battle City(优先队列 + BFS)

题目链接:POJ 2312 Battle City 打碎砖头x

fobdddf的专栏 666

POJ 2312 Battle City BFS+优先队列

POJ 2312 Battle City博客搬新家,以后就是基本只在自己的独立博客进行更新,欢迎访问。http://zihengoi.cn题目描述:  题目链接:POJ 2312 Battle City题目大意:  坦克大战游戏中需要让坦克(Y)(Y)在给定的地图中到达指定的位置(T)(T)。其中移动至空地(E)(E)算一次操作,砖墙(B)(B)因为需要先打破再通过故算两次操作,金属墙和河不能通过。

Running Boy的AC Dream 495

POJ 2312 Battle City 【BFS + 优先队列】

Many of us had played the game “Battle city” in our childhood, and some people (like me) even often play it on computer now. What we are discussing is a simple edition of this game. Given a...

qq_42445959的博客 304

POJ 2312 Battle City【Bfs+优先队列】

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8114   Accepted: 2716 Description Many of us had played the game "Battle city"

mengxiang000000 659

POJ 2312 Battle City (优先队列 + BFS)

Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8127   Accepted: 2724 Description Many of us had played the game "Battle city" in our childhood,

MADE_Y 374
上一篇: 二进制在数学中的妙用
下一篇: 程序员面试100题之十三:求二叉查找树的镜像
hackbuteer1
博客等级 码龄15年 1万+粉丝 251原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值