War Chess bfs+优先队列
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.
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+优先队列的更多相关文章
- 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 ...
- hdu 3345 War Chess
War Chess Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- POJ - 2312 Battle City BFS+优先队列
Battle City Many of us had played the game "Battle city" in our childhood, and some people ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
- POJ 1724 ROADS(BFS+优先队列)
题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...
- hdu 1242 找到朋友最短的时间 (BFS+优先队列)
找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)
题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...
随机推荐
- Codeforces D - GCD of Polynomials
D - GCD of Polynomials 逆推,根据(i-2)次多项f(i-2)式和(i-1)次多项式f(i-1)推出i次多项式f(i) f(i)=f(i-1)*x+f(i-2) 样例已经给出0次 ...
- ubuntu16.04 安装NVIDIA和CUDA9.2 cudNN7.1
1.安装NVIDIA驱动 (1)查询NVIDIA驱动 首先去官网(http://www.nvidia.com/Download/index.aspx?lang=en-us)查看适合自己显卡的驱动(下载 ...
- 20161208xlVBA工作表数据导入Access
Sub InsertToDataBase() Dim DataPath As String Dim SQL As String Const DataName As String = "yun ...
- dubbo监控报错Error creating bean with name 'uriBrokerService'
在jdk1.8下面会出现此错误 解决方法: 1.更换服务器jdk版本.(会影响其他项目环境) 2.修改dubbo-admin tomcat默认jdk版本. 3.修改dubbo-admin项目依赖(de ...
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
- Sergey's problem CodeForces - 1019C (图论,构造,神题)
链接 大意: 给定有向图, 求选择一个点集$S$, 使得$S$任意两点不相连, 且对于不属于$S$的任意点$x$, 均存在$S$中的点$y$, 使得$d(x,y)<=2$, $d(x,y)$为从 ...
- 处理Oracle EBS R12登录首页跳转出现unexpected error问题(转)
原文地址: 处理Oracle EBS R12登录首页跳转出现unexpected error问题 经上网搜索,造成此问题的问题有很多,如内存不足.系统参数配置不当.程序代码.系统表空间不足等原因.查询 ...
- php中点击网页不跳转执行程序
if($code['result_code'] !='FAIL') { echo "<script type='text/javascript'> alert('退款成功,请耐心 ...
- elasticsearch 路由文档到分片
路由文档到分片 当你索引一个文档,它被存储在单独一个主分片上.Elasticsearch是如何知道文档属于哪个分片的呢?当你创建一个新文档,它是如何知道是应该存储在分片1还是分片2上的呢? 进程不能是 ...
- 【CSS】清除浮动的五种方式
清除浮动是一件功德无量的事情23333 这里记录一下清除浮动的多种方式 *首先要明确的是,为什么要清除浮动? A 影响其他元素定位 父盒子高度为0,子盒子全部浮动.定位,子盒子不会撑开父盒子,下面的元 ...