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需要一分钟. ...
随机推荐
- RadioButtonList绑定后台的数据。
在前台,放置一个 <td style="width: 650px;"><asp:RadioButtonList ID="RadioButtonList2 ...
- 图像局部显著性—点特征(SiftGPU)
SIFT的计算复杂度较高. SiftGpu的主页:SiftGPU: A GPU Implementation of ScaleInvariant Feature Transform (SIFT) 对S ...
- 机器学习K-Means
1.K-Means聚类算法属于无监督学习算法. 2.原理:先随机选择K个质心,根据样本到质心的距离将样本分配到最近的簇中,然后根据簇中的样本更新质心,再次计算距离重新分配簇,直到质心不再发生变化,迭代 ...
- windows开机自启动bat脚本设置
群里有朋友问到windows下如何设计开机自启动的脚本,一般而言小鱼大多还是在linux环境下运维,windows的bat了解的很少,windows运行机制也不是特别了解,不过既然朋友问到这个问题,虽 ...
- ArchLinux简单介绍
一.Archlinux的由来 2002年由加拿大的Judd Vinet,Archlinux的创始人 怀着对Debian.Redhat的包管理器不满,于是创建了Archlinux!目前ArchLinux ...
- Idea里面的postfix
感谢慕课网IntelliJ IDEA神器使用技巧 闪电侠讲师,感觉有些工具真的是听听别人讲的比自己琢磨快很多 https://www.imooc.com/learn/924 也可以这样找到postfi ...
- tp5 权限设置
============================== <?php/** * Created by PhpStorm. * User: 14155 * Date: 2018/11/10 * ...
- 【ZOJ 4060】Flippy Sequence
[链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...
- mybatis源码阅读-Transaction和TransactionFactory(四)
Transaction 类图 接口定义 public interface Transaction { Connection getConnection() throws SQLException; v ...
- IDEA入门级使用教程
原文链接:https://blog.csdn.net/qq_31655965/article/details/52788374 最智能的IDE IDEA相对于eclipse来说最大的优点就是它比ecl ...