nyoj 284 坦克大战 简单搜索
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284
题意:在一个给定图中,铁墙,河流不可走,砖墙走的话,多花费时间1,问从起点到终点至少需要多少时间。
思路:简单广搜~
代码如下:
#include "stdio.h" //nyoj 284 坦克大战 简单搜索
#include "string.h"
#include "queue"
using namespace std; #define N 305
#define INF 0x3fffffff int n,m;
char map[N][N];
int Time[N][N];
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; struct node
{
int x,y;
int time;
}start,end; bool Budge(node a)
{
if(a.x<0 || a.x>=n || a.y<0 || a.y>=m || map[a.x][a.y]=='S' || map[a.x][a.y]=='R')
return true;
return false;
} int BFS()
{
int i;
queue<node> q;
q.push(start);
node cur,next;
while(!q.empty())
{
cur = q.front();
q.pop();
for(i=0; i<4; ++i)
{
next.x = cur.x+dir[i][0];
next.y = cur.y+dir[i][1];
if(Budge(next)) continue; //该点越界或不可走,continue;
next.time = cur.time+1;
if(map[next.x][next.y]=='B')
next.time++;
if(next.time<Time[next.x][next.y]) //该点访问的时间比原时间短,更新时间并将点加入队列
{
Time[next.x][next.y] = next.time;
q.push(next);
}
}
}
if(Time[end.x][end.y]==INF) return -1;
return Time[end.x][end.y];
} int main()
{
int i,j;
while(scanf("%d %d",&n,&m),n||m)
{
getchar();
for(i=0;i<n; ++i)
scanf("%s",map[i]);
for(i=0; i<n; ++i)
{
for(j=0; j<m;++j)
{
Time[i][j] = INF;
if(map[i][j]=='Y')
start.x=i,start.y=j,start.time=0;
if(map[i][j]=='T')
end.x=i,end.y=j;
}
}
printf("%d\n",BFS());
}
return 0;
}
nyoj 284 坦克大战 简单搜索的更多相关文章
- NYOJ 284 坦克大战 【BFS】+【优先队列】
坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 Many of us had played the game "Battle city" ...
- nyoj 284 坦克大战 (优先队列)
题目链接:http://acm.nyist.net/JudgeOnline/status.php?pid=284 特殊数据: 5 5 BBEEY EEERB SSERB SSERB SSETB 7 非 ...
- NYOJ 284 坦克大战 bfs + 优先队列
这类带权的边的图,直接广搜不行,要加上优先队列,这样得到的结果才是最优的,这样每次先找权值最小的,代码如下 #include <stdio.h> #include <iostream ...
- NYOJ 284 坦克大战 (广搜)
题目链接 描述 Many of us had played the game "Battle city" in our childhood, and some people (li ...
- java制作简单的坦克大战
坦克大战是我们小时候玩红白机时代的经典游戏,看到有不少小伙伴都使用各种语言实现了一下,手痒痒,也使用java做的一个比较简单的坦克大战,主要面向于学过Java的人群,与学了一段时间的人,有利于面向对象 ...
- 【blade04】用面向对象的方法写javascript坦克大战
前言 javascript与程序的语言比如C#或者java不一样,他并没有“类”的概念,虽然最新的ECMAScript提出了Class的概念,我们却没有怎么用 就单以C#与Java来说,要到真正理解面 ...
- FC 坦克大战 老巢铁墙
老巢外围铁墙E2A9:AC 80 EFEF80:A5 10 85 45 A5 45 AC D2 E2 用十六进制编辑器打开坦克大战的游戏文件搜索A5 45 F0 25 A5 0B改为AC 80 EF ...
- nyoj-----284坦克大战(带权值的图搜索)
坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" ...
- javascript 面向对象制作坦克大战 (一)
PS:这个坦克大战是在网上下的一段源码之后,自己进行的重写. 写这个的目的是为了巩固自己这段时间对js的学习.整理到博客上,算是对自己近端时间学习js的一个整理. 同时也希望可以帮助到学习js的园 ...
随机推荐
- LeetCode - 30. Substring with Concatenation of All Words
30. Substring with Concatenation of All Words Problem's Link --------------------------------------- ...
- Discuz的缓存体系
参考文档:<http://dev.discuz.org/wiki/index.php?title=缓存机制> Discuz中涉及数据缓存的地方有: 1. session Dz的sessio ...
- 一、PBNI环境搭建及初步使用
PowerBuilder Native Interface(PowerBuilder本机接口PBNI)允许将第3方程序转换为PowerBuilder对象,供PowerBuilder直接使用,也允许将P ...
- .NET Core的“dotnet restore”、“dotnet build”和“dotnet run”命令都是用来干什么的?
dotnet restore 源代码:https://github.com/dotnet/cli/tree/rel/1.0.0/src/dotnet/commands/dotnet-restore 入 ...
- C#6.0语法糖剖析(二)
1.索引初始化 使用代码 ] = ] = ] = "thirteen"}; 编译器生成的代码 Dictionary<int, string> dictionary2 = ...
- ES6中generator传参与返回值
先看两个例子, 1, function* f() { for(var i=0; true; i++) { var reset = yield i; if(reset) { i = -1; } } } ...
- java调用html模板发送html内容的邮件
在项目需要发送邮件,普通内容的邮件觉得太单调.太丑,没逼格,所以说直接把用到的邮件内容做成一个html模板,发送之前将对应参数替换掉,发送html内容的高逼格邮件. 首先需要引用jar包,这就不多说了 ...
- 简单好用的Toast封装类——EasyToast
我们用toast时不能设置显示的时间,而且不支持在线程中展示toast,下面我对原始的toast进行了封装,这样我们可以很方便的进行toast的使用了. package com.kale.lib.ut ...
- 推荐几个优秀的java爬虫项目
java爬虫项目 大型的: Nutch apache/nutch · GitHub 适合做搜索引擎,分布式爬虫是其中一个功能. Heritrix internetarchive/heritrix3 ...
- 内置对象Clob对从数据库表中取的字符大对象CLOB类型的列值进行读取操作
package readclobDemo.bao; import java.io.IOException; import java.io.Reader; import java.sql.Clob; i ...