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
.*.

bfs扩展四个方向,消耗mv最少优先级最高,加入优先队列,优先扩展mv最高点。保证*扩展到最远边界。

代码150+。。写出来还蛮有成就感的。。

Status Accepted
Time 15ms
Memory 1620kB
Length 3170
Lang G++
Submitted 2017-07-21 00:33:46
Shared
RemoteRunId 21228675
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
char a[][];
int b[][];
int t[][]={{,},{,},{-,},{,-}};
struct Node{
int x,y,mv;
friend bool operator<(Node a,Node b)
{
return a.mv<b.mv;
}
}node;
int main()
{
int t1,n,m,mvp,f,i,j,k,l;
priority_queue<Node> q;
scanf("%d",&t1);
while(t1--){
scanf("%d%d%d",&n,&m,&mvp);
for(i=;i<n;i++){
getchar();
scanf("%s",a[i]);
}
memset(b,,sizeof(b));
for(i=;i<n;i++){
for(j=;j<m;j++){
if(a[i][j]=='Y'){
b[i][j]=;
node.x=i;
node.y=j;
node.mv=mvp;
q.push(node);
while(q.size()){
for(k=;k<;k++){
int tx=q.top().x+t[k][];
int ty=q.top().y+t[k][];
if(tx<||ty<||tx>=n||ty>=m) continue;
if(a[tx][ty]=='.'&&b[tx][ty]==){
if(q.top().mv-<) continue;
f=;
for(l=;l<;l++){
int ttx=tx+t[l][];
int tty=ty+t[l][];
if(ttx<||tty<||ttx>=n||tty>=m) continue;
if(a[ttx][tty]=='E'){
b[tx][ty]=;
a[tx][ty]='*';
f=;
continue;
}
}
if(f==) continue;
b[tx][ty]=;
a[tx][ty]='*';
node.x=tx;
node.y=ty;
node.mv=q.top().mv-;
q.push(node);
}
else if(a[tx][ty]=='T'&&b[tx][ty]==){
if(q.top().mv-<) continue;
f=;
for(l=;l<;l++){
int ttx=tx+t[l][];
int tty=ty+t[l][];
if(ttx<||tty<||ttx>=n||tty>=m) continue;
if(a[ttx][tty]=='E'){
b[tx][ty]=;
a[tx][ty]='*';
f=;
continue;
}
}
if(f==) continue;
b[tx][ty]=;
a[tx][ty]='*';
node.x=tx;
node.y=ty;
node.mv=q.top().mv-;
q.push(node);
}
else if(a[tx][ty]=='R'&&b[tx][ty]==){
if(q.top().mv-<) continue;
f=;
for(l=;l<;l++){
int ttx=tx+t[l][];
int tty=ty+t[l][];
if(ttx<||tty<||ttx>=n||tty>=m) continue;
if(a[ttx][tty]=='E'){
b[tx][ty]=;
a[tx][ty]='*';
f=;
continue;
}
}
if(f==) continue;
b[tx][ty]=;
a[tx][ty]='*';
node.x=tx;
node.y=ty;
node.mv=q.top().mv-;
q.push(node);
}
else if(a[tx][ty]=='#'&&b[tx][ty]==){
b[tx][ty]=;
continue;
}
else if(a[tx][ty]=='E'&&b[tx][ty]==){
b[tx][ty]=;
continue;
}
else if(a[tx][ty]=='P'&&b[tx][ty]==){
if(q.top().mv-<=) continue;
f=;
for(l=;l<;l++){
int ttx=tx+t[l][];
int tty=ty+t[l][];
if(ttx<||tty<||ttx>=n||tty>=m) continue;
if(a[ttx][tty]=='E'){
b[tx][ty]=;
f=;
continue;
}
}
if(f==) continue;
b[tx][ty]=;
node.x=tx;
node.y=ty;
node.mv=q.top().mv-;
q.push(node);
}
}
q.pop();
}
}
}
}
for(i=;i<n;i++){
printf("%s\n",a[i]);
}
printf("\n");
}
return ;
}

HDU - 3345 War Chess 广搜+优先队列的更多相关文章

  1. hdu 3345 War Chess

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

  2. hdu 1242:Rescue(BFS广搜 + 优先队列)

    Rescue Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  3. Combine String HDU - 5707 dp or 广搜

    Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...

  4. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  5. HDU 1253 (简单三维广搜) 胜利大逃亡

    奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 //#define LOCAL #include <ios ...

  6. hdu 1175 连连看 (广搜,注意解题思维,简单)

    题目 解析见代码 #define _CRT_SECURE_NO_WARNINGS //这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线 //所以应该把所有的路径都搜索出来,找到最短的转折数, ...

  7. hdu 1495 非常可乐 (广搜)

    题目链接 Problem Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶 ...

  8. HDU 1072 Nightmare (广搜)

    题目链接 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ...

  9. hdu 1240(三维广搜)

    题意: 有一个n*n*n的三维空间. 给你起始坐标和终点坐标.要你从起点到终点,问最少需要多少步走出去.如果走不出去则输出"NO ROUTE". 空间中 'O' 表示这个点可以走, ...

随机推荐

  1. 基于EfCore的一个多租户Demo

    六月份如愿的转入了架构组,先上手搞了个CI服务器,把架构组的几个项目撸到上面去了.效果不错,接着就把其他两个项目组有单元测试的项目撸上去了,在桌子上放了个显示器当大屏用. 因为公司准备进行一个大的系统 ...

  2. python的id()函数的一个小方面(转载)

    >>> a = 2 >>> b = 2 >>> id(a) 21132060 >>> id(b) 21132060 >&g ...

  3. SAM4E单片机之旅——8、UART初步

    通信还是比让LED灯闪烁实用得多的. 这次试试使用UART,实现开发版和PC间的通信.功能比较简单,就是把PC发向开发版的内容发送回去.这次主要介绍一下UART的配置,至于通信,则使用较为简单的不断查 ...

  4. request,session,application三者关系<转>

    几乎所有的Web开发语言都支持Session功能,Servlet也不例外. Servlet/JSP中的Session功能是通过作用域(scope)这个概念来实现的. 对象作用域为:  page  在当 ...

  5. python网络爬虫之使用scrapy下载文件

    前面介绍了ImagesPipeline用于下载图片,Scrapy还提供了FilesPipeline用与文件下载.和之前的ImagesPipeline一样,FilesPipeline使用时只需要通过it ...

  6. 解析json的方式

    一.Javascrip操作json 原始方式: var str1 = '{ "name": "jacun", "addr": "b ...

  7. 向HTML页面传入参数

    这次是想将参数传入HTML页面,通过js获取参数信息,动态生成HTML页面内容: 方法一: <script> function GetArgsFromHref(sHref, sArgNam ...

  8. Consul环境搭建

    大家在玩的时候 一定要使用ningx 1.9以上版本啊! 下载:wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_ ...

  9. webform中实现SQL Sever2008数据库数据分页查询

    1 分页     1.1         数据库中存储过程             已知 当前页  pageIndex  页容量 pageSize             求  总页数 pageCou ...

  10. node.js 开发博客系统

    1. 安装yoman :npm install -g yo 2. 安装 generator-express :npm install -g generator-express 3. 安装 bower ...