题目描述

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 map that consists of empty spaces, rivers, steel walls and brick walls only. Your task is to get a bonus as soon as possible suppose that no enemies will disturb you (See the following picture).

Your tank can't move through rivers or walls, but it can destroy brick walls by shooting. A brick wall will be turned into empty spaces when you hit it, however, if your shot hit a steel wall, there will be no damage to the wall. In each of your turns, you can choose to move to a neighboring (4 directions, not 8) empty space, or shoot in one of the four directions without a move. The shot will go ahead in that direction, until it go out of the map or hit a wall. If the shot hits a brick wall, the wall will disappear (i.e., in this turn). Well, given the description of a map, the positions of your tank and the target, how many turns will you take at least to arrive there?

输入

The input consists of several test cases. The first line of each test case contains two integers M and N (2 <= M, N <= 300). Each of the following M lines contains N uppercase letters, each of which is one of 'Y' (you), 'T' (target), 'S' (steel wall), 'B' (brick wall), 'R' (river) and 'E' (empty space). Both 'Y' and 'T' appear only once. A test case of M = N = 0 indicates the end of input, and should not be processed.

输出

For each test case, please output the turns you take at least in a separate line. If you can't arrive at the target, output "-1" instead.

样例输入

3 4
YBEB
EERE
SSTE
0 0

样例输出

8

再次回头复习bfs,突然发现优先队列忘记啦。。。。。。。。

#include <iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
int n,m;
char s[310][310];
int go[4][2]= {{1,0},{0,1},{0,-1},{-1,0}};
struct node
{int x,y,num;friend int operator<(node a,node b)//定义优先队列,步数少的队列{return a.num>b.num;}
} now,to;
int bfs(int x,int y)
{priority_queue<node>q;//创建优先队列now.num=0;now.x=x;now.y=y;q.push(now);while(!q.empty()){now=q.top();q.pop();for(int i=0; i<4; i++){int xx=now.x+go[i][0];int yy=now.y+go[i][1];if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='E'){to.num=now.num+1;to.x=xx;to.y=yy;q.push(to);s[xx][yy]='S';}else if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='B'){to.num=now.num+2;to.x=xx;to.y=yy;q.push(to);s[xx][yy]='S';}else if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='T'){to.num=now.num+1;return to.num;}}}return 0;
}
int main()
{while(~scanf("%d%d",&n,&m)){int x1,y1;if(n==0&&m==0)return 0;for(int i=0; i<n; i++){scanf("%s",s[i]);for(int j=0; j<m; j++){if(s[i][j]=='Y'){x1=i;y1=j;}}}int pp=bfs(x1,y1);if(pp)printf("%d\n",pp);elseprintf("-1\n");}return 0;
}

坦克大战 bfs 优先队列相关推荐

  1. nyoj 284 坦克大战 (优先队列)

    题目链接:http://acm.nyist.net/JudgeOnline/status.php?pid=284 特殊数据: 5 5 BBEEY EEERB SSERB SSERB SSETB 7 非 ...

  2. nyoj284 坦克大战(dijkstra(bfs+优先队列))

    题目284 题目信息 运行结果 本题排行 讨论区 坦克大战 时间限制: 1000 ms  |  内存限制: 65535 KB 难度: 3 描述 Many of us had played the ga ...

  3. nyoj 284 坦克大战【bfs】

    坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" i ...

  4. 坦克大战(bfs简单变形)

    坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" i ...

  5. NYOJ-284 坦克大战

    坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" i ...

  6. 基于Netty的联机版坦克大战

    基于Netty的联机版坦克大战 项目介绍 项目github地址:基于Netty的联机版坦克大战 该项目实现了联机版坦克大战,项目包括客户端与服务端 项目使用技术: 使用Netty实现客户端和服务端之间 ...

  7. 优先级队列广搜——坦克大战

    坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" in ...

  8. 【跟我一起学Unity3D】做一个2D的90坦克大战之AI系统

    对于AI,我的初始想法非常easy,首先他要能动,而且是在地图里面动. 懂得撞墙后转弯,然后懂得射击,其它的没有了,基于这个想法,我首先创建了一个MyTank类,用于管理玩家的坦克的活动,然后创建AI ...

  9. 用Python实现坦克大战游戏 | 干货贴

    作者 | 李秋键 出品 | AI科技大本营(rgznai100) <坦克大战>是1985年日本南梦宫Namco游戏公司在任天堂FC平台上,推出的一款多方位平面射击游戏.游戏以坦克战斗及保卫 ...

最新文章

  1. 红黑树效率为甚恶魔是log_一文带你彻底读懂红黑树(附详细图解)
  2. android 6.0 sd卡读写权限,Android 6.0 读写SD卡权限问题
  3. wait_timeout【Mysql】解决方案
  4. Grunt教程——安装Grunt
  5. 2021未来职业规划以及对过去的总结
  6. Python3 装饰器解析
  7. java 内省机制_Java反射与内省机制总结
  8. 95-190-450-源码-window-Trigger-ContinuousProcessingTimeTrigger
  9. 如何将js加入到HTML中
  10. Python数据可视化1.5 可视化图像
  11. java苹果沙盒验证参数问题_php – iOS7 – 收据未在沙盒验证 – 错误21002(java.lang.IllegalArgumentException)...
  12. 深度学习 --- BP算法详解(误差反向传播算法)
  13. ui设计移动端字体适配_UI设计师设计移动端界面要注意的字体规范有那些?
  14. (一文读懂社交网络分析(附应用、前沿、学习资源)学习笔记)
  15. MFC+HPSocket+log4cplus的TCP助手(三、HPSocket)
  16. python isupper_一日一技:python中的string.isupper方法
  17. 基于CISe@ZnS新型近红外二区量子点生物探针(CuInS2/ZnS量子点,Cd掺杂ZnO量子点,InP/ZnS,荧光Ag2S量子点)
  18. 云呐|固定资产管理的目的,固定资产管理办法的目的
  19. PMP第二轮复习:整本书内容融会贯通
  20. Ubuntu18.04/20.04 上微信中文显示为方块状乱码的解决方案( Deepin-Wechat )

热门文章

  1. 龙芯3B处理器—地址映射以及路由地址分布与配置
  2. 项目四:飞机票订票管理系统
  3. 航空发动机试车台-喘振、整机振动监测方向论文资料阅读整理【0】
  4. 前 Twitter CEO 炮轰 Web 3,马斯克也来“掺和一脚”
  5. 一款可以录音示爱的蓝牙音响,这么有心机的告白我给满分丨钛空智慧星球推荐
  6. 《蓝桥杯真题》:1.自动售水机
  7. ECMA5forEach
  8. 边缘检测一 一阶微分算子
  9. Verilog HDL经典电路设计
  10. 基于Python的智能分班系统