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需要一分钟. ...
随机推荐
- Tomcat 程序无问题的情况下页面打开变慢的原因
看看这写日志的频率就知道我有多闲了.. 前言: 其实关于tomcat,遇到过很多关于“慢”的问题,比如启动慢,比如页面打开慢, 以前太忙也太懒,不愿意花时间分析原因,现在终于肯静下来找原因 环境是ec ...
- Laravel5.1学习笔记10 系统架构2 应用程序结构
应用程序结构 简介 根目录 App 目录 为应用程序设置命名空间 简介 默认的 Laravel 应用程序结构是为了给无论构建大型还是小型应用程序都提供一个良好的开始.当然,你可以依照喜好自由地组织应用 ...
- backface-visibility当元素不面向屏幕时是否可见
html代码 <h1>div1可见</h1> <div class="div1">div---1</div> <h1>d ...
- bootstrap模态框和select2合用时input无法获取焦点(转)
在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入. 解决方法: 1. 把页面中的 tabindex="-1&qu ...
- Flutter GitLab 客户端
F4Lab Flutter for GitLab. 欢迎参加一起完成
- ★Java语法(六)——————————分支语句
1. if 语句 格式用法: if(布尔表达式) { 语句: } 2. if……else 语句 格式用法: if(表达式) { 语句1: } else { 语句2: } 3.if……else i ...
- Assembly之instruction之Register Mode
Assembler Code Content of ROM MOV R10,R11 MOV R10,R11 Length: One or two words Operation: Move the c ...
- (转)Bootstrap 之 Metronic 模板的学习之路 - (2)源码分析之 head 部分
https://segmentfault.com/a/1190000006684122 下面,我们找个目录里面想对较小的文件来分析一下源码结构,我们可以看到,page_general_help.htm ...
- Docker 数据卷重复挂载测试
没想到一年没写博客了,这中间都是记在自己的笔记本上,大部分网上都有,这个好像没有,所以发上来吧! 本文是测试Docker容器(相同目录/父子目录)同时挂载到宿主机(同目录/不同目录)时的情况,废话少说 ...
- VS 2017 统计项目代码总行数
编辑 → 查找和替换 → 在文件中的查找,打开查找窗口 填入正则表达式 ^b*[^:b#/]+.*$ 查找范围选“整个解决方案”,勾选上“使用正则表达式” 如果要限制文件类型,就填上要查找的文件类型 ...