War chess is hh's favorite game:
In this game, there is an N * M battle map, and every player has
his own Moving Val (MV). In each round, every player can move in four
directions as long as he has enough MV. To simplify the problem, you are
given your position and asked to output which grids you can arrive.




In the map:

'Y' is your current position (there is one and only one Y in the given map).

'.' is a normal grid. It costs you 1 MV to enter in this gird.

'T' is a tree. It costs you 2 MV to enter in this gird.

'R' is a river. It costs you 3 MV to enter in this gird.

'#' is an obstacle. You can never enter in this gird.

'E's are your enemies. You cannot move across your enemy, because
once you enter the grids which are adjacent with 'E', you will lose all
your MV. Here “adjacent” means two grids share a common edge.

'P's are your partners. You can move across your partner, but you
cannot stay in the same grid with him final, because there can only be
one person in one grid.You can assume the Ps must stand on '.' . so ,it
also costs you 1 MV to enter this grid.
InputThe first line of the inputs is T, which stands for the number of test cases you need to solve.

Then T cases follow:

Each test case starts with a line contains three numbers N,M and MV
(2<= N , M <=100,0<=MV<= 65536) which indicate the size of
the map and Y's MV.Then a N*M two-dimensional array follows, which
describe the whole map.OutputOutput the N*M map, using '*'s to replace all the grids 'Y'
can arrive (except the 'Y' grid itself). Output a blank line after each
case.Sample Input

5
3 3 100
...
.E.
..Y 5 6 4
......
....PR
..E.PY
...ETT
....TT 2 2 100
.E
EY 5 5 2
.....
..P..
.PYP.
..P..
..... 3 3 1
.E.
EYE
...

Sample Output

...
.E*
.*Y ...***
..**P*
..E*PY
...E**
....T* .E
EY ..*..
.*P*.
*PYP*
.*P*.
..*.. .E.
EYE
.*.

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
int dir[][]={,,,,,-,-,};
int t,n,m,val,head,tail,tx,ty,d;
char map[][]; int vis[][];
struct que
{
int x,y,mv;
friend bool operator <(que a,que b)
{
return a.mv<b.mv;
}
}cur;
int judge(int x,int y)
{
if(x<||y<||x>=n||y>=m)return ;
return ;
}
int check(int x,int y)
{
for(int i=;i<;i++)
if(judge(x+dir[i][],y+dir[i][])&&map[x+dir[i][]][y+dir[i][]]=='E')return ;
return ;
}
int check1(int x,int y)
{
if(vis[x][y]<)return ;
if(map[x][y]=='P'||map[x][y]=='Y')return ;
return ;
}
int main()
{
priority_queue <que>q;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&val);
head=tail=;
memset(vis,-,sizeof(vis));
for(int i=;i<n;i++)
scanf("%s",map[i]);
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(map[i][j]=='Y'){
cur.x=i,cur.y=j;
cur.mv=val;
q.push(cur);
vis[i][j]=val;
break;}
}
} while(!q.empty())
{
for(int i=;i<;i++)
{
tx=q.top().x+dir[i][];
ty=q.top().y+dir[i][];
if(!judge(tx,ty)||map[tx][ty]=='#'||map[tx][ty]=='E')continue;
if(map[tx][ty]=='T')d=q.top().mv-;
else if(map[tx][ty]=='R')d=q.top().mv-;
else d=q.top().mv-;
if(check(tx,ty)&&d>)d=;
if(d>vis[tx][ty])
{
vis[tx][ty]=d;
if(d>)
{cur.x=tx;
cur.y=ty;
cur.mv=d;
q.push(cur);}
}
}
q.pop();
} for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(check1(i,j))putchar('*');
else putchar(map[i][j]);
}
cout<<endl;
}
cout<<endl;
}
}

War Chess bfs+优先队列的更多相关文章

  1. HDU - 3345 War Chess 广搜+优先队列

    War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...

  2. hdu 3345 War Chess

    War Chess Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  3. POJ - 2312 Battle City BFS+优先队列

    Battle City Many of us had played the game "Battle city" in our childhood, and some people ...

  4. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  5. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  6. POJ 1724 ROADS(BFS+优先队列)

    题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...

  7. hdu 1242 找到朋友最短的时间 (BFS+优先队列)

    找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...

  8. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

  9. hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)

    题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...

随机推荐

  1. Python 爬虫-正则表达式(补)

    2017-08-08 18:37:29 一.Python中正则表达式使用原生字符串的几点说明 原生字符串和普通字符串的不同 相较于普通字符串,原生字符串中的\就是反斜杠,并不表达转义.不过,字符串转成 ...

  2. Python 错误与异常

    2017-08-01 13:40:17 在程序运行过程中,总会遇到各种各样的错误. 有的错误是程序编写有问题造成的,比如本来应该输出整数结果输出了字符串,这种错误我们通常称之为bug,bug是必须修复 ...

  3. template.js 模版内调用外部JS方法

    template.js 一款 JavaScript 模板引擎,简单,好用.提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同的效果.模版定义如下: ...

  4. python-day52--前端html、css

    一.html需掌握的: 1. img标签 属性:src alt title width height 2. a标签 属性:href target 3. ul 标签及li 标签,二者都是块级标签 ul ...

  5. logback 范例

    <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false ...

  6. Kubernetes设计架构

    官方文档:https://www.kubernetes.org.cn/doc-11 Kubernetes集群包含有节点代理kubelet和Master组件(APIs, scheduler, etc), ...

  7. spring的FactoryBean

    (以下内容翻译自spring/docs/3.2.18.RELEASE) 为具有工厂属性的对象实现FactoryBean接口. FactoryBean接口是spring IoC 容器实例化逻辑的一点补充 ...

  8. anaconda环境变量+修改jupyter默认路径

    手贱在安装的时候没有点添加环境变量 安装好后,用anaconda prompt运行一些程序命令之类都是可以的,但是直接打开cmd就不行了,为了省事,所以决定手动添加环境变量, %\ProgramDat ...

  9. 通过ReRes让chrome拥有路径映射的autoResponse功能。

    前端开发过程中,经常会有需要对远程环境调试的需求.比如,修改线上bug,开发环境不在本地等等.我们需要把远程css文件或者js映射到本地的文件上,通过修改本地文件进行调试和开发.通常我们可以通过以下方 ...

  10. linux pipes

    In Linux, a pipe is implemented using two filedata structures which both point at the same temporary ...