Battle City
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7208 | Accepted: 2427 |
Description

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?
Input
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.
Output
Sample Input
3 4
YBEB
EERE
SSTE
0 0
Sample Output
8
Source
POJ Monthly,鲁小石
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
char map[1010][1010];
int vis[1010][1010],m,n,x,y;
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
struct node
{
int x,y;
int step;
friend bool operator < (node n1,node n2)
{
return n1.step>n2.step;
}
}p,temp;
int judge(node s)
{
if(s.x<0||s.x>=m||s.y<0||s.y>=n)
return 1;
if(map[s.x][s.y]=='S'||map[s.x][s.y]=='R')
return 1;
if(vis[s.x][s.y])
return 1;
return 0;
}
int bfs()
{
priority_queue<node>q;
p.x=x;p.y=y;
p.step=0;
memset(vis,0,sizeof(map));
vis[x][y]=1;
q.push(p);
while(!q.empty())
{
p=q.top();
q.pop();
for(int i=0;i<4;i++)
{
temp.x=p.x+dx[i];
temp.y=p.y+dy[i];
if(judge(temp)) continue;
if(map[temp.x][temp.y]=='B')
temp.step=p.step+2;
else temp.step=p.step+1;
if(map[temp.x][temp.y]=='T')
return temp.step;
vis[temp.x][temp.y]=1;
q.push(temp);
}
}
return -1;
}
int main()
{
while(scanf("%d%d",&m,&n),m||n)
{
int i,j;
for(i=0;i<m;i++)
{
scanf("%s",map[i]);
for(j=0;j<n;j++)
{
if(map[i][j]=='Y')
{
x=i;y=j;
}
}
}
printf("%d\n",bfs());
}
return 0;
}
Battle City的更多相关文章
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...
- poj 2312 Battle City【bfs+优先队列】
Battle City Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7579 Accepted: 2544 Des ...
- B - Battle City bfs+优先队列
来源poj2312 Many of us had played the game "Battle city" in our childhood, and some people ( ...
- POJ 2312:Battle City(BFS)
Battle City Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9885 Accepted: 3285 Descr ...
- Battle City 优先队列+bfs
Many of us had played the game "Battle city" in our childhood, and some people (like me) e ...
- POJ - 2312 Battle City BFS+优先队列
Battle City Many of us had played the game "Battle city" in our childhood, and some people ...
- C - Battle City BFS+优先队列
Many of us had played the game "Battle city" in our childhood, and some people (like me) e ...
- poj2312 Battle City 【暴力 或 优先队列+BFS 或 BFS】
题意:M行N列的矩阵.Y:起点,T:终点.S.R不能走,走B花费2,走E花费1.求Y到T的最短时间. 三种解法.♪(^∇^*) //解法一:暴力 //157MS #include<cstdio& ...
- poj 2312 Battle City(优先队列+bfs)
题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...
随机推荐
- Laravel5.1学习笔记3 HTTP中间件
HTTP 中间件 简介 建立中间件 注册中间件 可终止中间件 简介 HTTP 中间件提供一个方便的机制来过滤进入应用程序的 HTTP 请求,例如,Laravel 默认包含了一个中间件来检验用户身份验证 ...
- 上传预览图片的插件jquery-fileupload
上传预览图片的插件jquery-fileupload github地址:https://github.com/blueimp/jQuery-File-Upload 中文文档:http://www.jq ...
- 彻底去除Google AdMob广告
应用中包含广告是能够理解的,但经常造成用户误点,或者广告切换时造成下载流量,就有点让人不舒服了. 以下就以Google AdMob广告为例,看怎样彻底去除他. 先分析一下Google AdMob的工作 ...
- [Intermediate Algorithm] - Drop it
题目 队友该卖就卖,千万别舍不得. 当你的队伍被敌人包围时,你选择拯救谁.抛弃谁非常重要,如果选择错误就会造成团灭. 如果是AD或AP,优先拯救. 因为AD和AP是队伍输出的核心. 其次应该拯救打野. ...
- 我的最爱Lambda演算——开篇
(在这个帖子的原始版本里,我试图用一个JavaScript工具来生成MathML.但不太顺利:有几个浏览器没法正确的渲染,在RSS feed里也显示的不好.所以我只好从头开始,用简单的文本格式重新写一 ...
- 判断input或者div.span等标签是否存在
//用jQuery检查某个元素在网页上是否存在时,应该根据获取元素的长度来判断,代码如下 if($("#email"+i).length > 0){//判断input是否存在 ...
- esp32使iOS 获取蓝牙外设的Mac地址
最近在做一个需要上下位机的项目,我负责的任务下位机,使用的主控芯片是esp32.这个项目中有一项是需要手机扫描二维码然后连接作为esp32的蓝牙.二维码中包含了mac地址信息,在手机扫描周围设备的时候 ...
- 图的BFS
目录: 一.算法的基本思路 二.算法过程 三.题目:785判断是否为二分图 https://blog.csdn.net/weixin_40953222/article/details/80544928 ...
- 关于swift 底部工具栏图标锯齿模糊问题。
今天在底部工具栏添加图片时发现图片模糊而且有锯齿,开始一直以为是美工给的图片有问题,后来发现是要设置两种图片: 比如 index.png(默认30 * 30),indexSelected(选中后的图 ...
- 博弈论题目总结(二)——SG组合游戏及变形
SG函数 为了更一般化博弈问题,我们引入SG函数 SG函数有如下性质: 1.如果某个状态SG函数值为0,则它后继的每个状态SG函数值都不为0 2.如果某个状态SG函数值不为0,则它至少存在一个后继的状 ...