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. 简明Docker教程

    Docker基础 这篇基础文章是方便用户在使用cSphere平台之前,了解docker基础知识. 针对已经有一定的Linux基础知识的用户. Docker是什么 Docker是一个改进的容器技术.具体 ...

  2. 怒学Java8系列一:Lambda表达式

    PDF文档已上传Github  Github:https://github.com/zwjlpeng/Angrily_Learn_Java_8 第一章 Lambda 1.1 引言 课本上说编程有两种模 ...

  3. HTTP URL 字符转义 字符编码 、 RFC 3986编码规范

    一.为什么要编码转义 通常如果一样东西需要编码,说明这样东西并不适合传输.原因多种多样,如Size过大,包含隐私数据,对于Url来说,之所以要进行编码,是因为Url中有些字符会引起歧义. 例如Url参 ...

  4. Johnny Solving CodeForces - 1103C (构造,图论)

    大意: 无向图, 无重边自环, 每个点度数>=3, 要求完成下面任意一个任务 找一条结点数不少于n/k的简单路径 找k个简单环, 每个环结点数小于n/k, 且不为3的倍数, 且每个环有一个特殊点 ...

  5. mxnet(gluon) 实现DQN简单小例子

    参考文献 莫凡系列课程视频 增强学习入门之Q-Learning 关于增强学习的基本知识可以参考第二个链接,讲的挺有意思的.DQN的东西可以看第一个链接相关视频.课程中实现了Tensorflow和pyt ...

  6. dp练习(7)—— 最小和

    3415 最小和 CodeVS原创  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 青铜 Bronze 题解       题目描述 Description 小浣熊松松来到文具店, ...

  7. Java远程调试 java -Xdebug各参数说明

    JAVA自身支持调试功能,并提供了一个简单的调试工具--JDB,类似于功能强大的GDB,JDB也是一个字符界面的 调试环境,并支持设置断点,支持线程线级的调试 JAVA的调试方法如下: 1.首先支持J ...

  8. JavaScript学习总结(四)——逻辑OR运算符详解

    在JavaScript中,逻辑OR运算符用||表示 1 var bTrue = true; 2 var bFalse = false; 3 var bResult = bTrue || bFalse; ...

  9. PHP:第二章——PHP中的foreach语句

    foreach语句提供了遍历数组的 <?php header("Content-Type:text/html;charset=utf-8"); $arr=array(&quo ...

  10. bzoj1626

    题解: 简单最小生成树 x,y都要double 我也不知道为什么 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,f[ ...