War Chess bfs+优先队列

时间:2022-12-05 01:25:53
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.


War Chess bfs+优先队列

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 广搜&plus;优先队列

    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&plus;优先队列

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

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

    #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&lpar;BFS&plus;优先队列&rpar;

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

  7. hdu 1242 找到朋友最短的时间 &lpar;BFS&plus;优先队列&rpar;

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

  8. HDU 1428 漫步校园 &lpar;BFS&plus;优先队列&plus;记忆化搜索&rpar;

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

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

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

随机推荐

  1. 带你玩转JavaWeb开发之六-mysql基本语法详解及实例&lpar;3&rpar;

    [语法] update 表名 set 列名=列值,列名=列值 -[条件]; [注意事项] * 修改的列的值需要与列的类型一致. * 修改的列的值的长度不能超过列的类型的最大长度. * 字符串类型和日期 ...

  2. PHP Multipart&sol;form-data remote dos Vulnerability

    catalog . Description . Analysis 1. Description PHP is vulnerable to a remote denial of service, cau ...

  3. Asp&period;Net Web API 2第十四课——Content Negotiation&lpar;内容协商&rpar;

    前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/3446289.html 本文描述ASP.NET W ...

  4. js实现鼠标点击input框后里面的内容就消失代码

    <!--# <a href="http://www.mianfeimoban.com/texiao_mb/" target="_blank" cla ...

  5. vim 跳到指定行

    在编辑模式下输入 ngg 或者 nG n为指定的行数(如25) 25gg或者25G 跳转到第25行. 在命令模式下输入行号n : n 如果想打开文件即跳转 vim +n FileName 查看当然光标 ...

  6. 全栈一路坑之使用django创建博客

    最近在看一篇全栈增长工程师实战,然后学习里面的项目,结果发现作者用的技术太过老旧,好多东西都已经被抛弃了,所以结合着官方文档和自己的一些理解将错误的信息替换一下,边写边学习 准备工作和工具 作者说需要 ...

  7. selenium打开带有扩展的chrome

    每当用跑用例失败的时候,第一反应就是查看元素定位是不是正确,帮助定位的扩展是必不可少的,但是selenium一般打开的是不带扩展的干净的浏览器,如果操作步骤很长的话,就得手动去执行直到那一步去检查元素 ...

  8. 关于OJ的输入和输出&lpar;转&rpar;

    ACM竞赛之输入输出以下内容来源于互联网.在ACM程序设计竞赛中,一道题目的所有测试数据是放在一个文本文件中,选手将一道题目的程序提交给评判系统运行,程序从该文件中读取测试数据,再把运行结果输出到另一 ...

  9. Android ListView&plus;image的使用

    首先创建layout部局文件xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayo ...

  10. &dollar;&period;fn、&dollar;&period;fn&period;extend和&dollar;&period;extend的区别

    $.fn $.fn是指jquery的命名空间,加在fn上的方法及属性,会对jquery实例每一个有效. 如:扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后 ...