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可以承受的最大容量... ...
随机推荐
- angular5中使用echart的方法
注意两点安装的版本 安装好后可以参照echart的官网使用 1.实现package.json中安装这两个包 2.index.html中引入 3.在appModule中添加 然后再html中就可以这么使 ...
- ASCII 可打印字符与控制字符
2017-08-16 21:29:30 基本的 ASCII 字符集共有 128 个字符,其中有 95 个可打印字符,包括常用的字母.数字.标点符号等,另外还有 33 个控制字符.标准 ASCII 码使 ...
- C# DataTable按指定列排序
C#提供的内置对象DataTable功能特别的强大,如果我们需要对DataTable中的某一列进行排序怎么处理呢,具体代码如下: DataTable dt = new DataTable(); dt. ...
- 20170813pptVBA批量插入图片
Sub AddSldIn() Dim Pre As Presentation Dim NewSld As Slide Set Pre = Application.ActivePresentation ...
- 关于pthread_cond_wait()使用的理解
pthread_cond_wait()是linux多线程同步实现的一种方法,表示等待某一个线程共享变量满足了某种情况时 线程才能继续执行 pthread_cond_wait()之后的代码,如下面的示例 ...
- Jersey 2.x 从Maven Archetype 创建一个新项目
创建 Jersey 工程需要使用 Apache 的 Maven 软件工程和管理工具.所有的Jersey产品模块都可以在 Maven中央库 中找到.这样的话 Jersey 可以非常容易和其他基于 Mav ...
- python-day8-字典的内置方法
# info=['egon','male',18,180,75]### info_dic={'name':'egon','age':18,'sex':'male'} # 有对应关系 # 常用操作:优先 ...
- Wannafly挑战赛20-A,B
A-链接:https://www.nowcoder.com/acm/contest/133/A来源:牛客网 题目描述 现在有一棵被Samsara-Karma染了k种颜色的树,每种颜色有着不同的价值 A ...
- ES profile 性能优化用——返回各个shard的耗时
Profile API 都说要致富先修路,要调优当然需要先监控啦,elasticsearch在很多层面都提供了stats方便你来监控调优,但是还不够,其实很多情况下查询速度慢很大一部分原因是糟糕的查询 ...
- wordpress 使用less 样式无法及时刷新
wordpress 样式无法及时刷新 wordpress编写style样式时,无法及时刷新页面,因此特意记录一番如何处理较好,网友的建议清除Chrome缓存,实时修改style携带的参数 折腾之旅开启 ...