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. Django-extra的用法

    ## select提供简单数据 # SELECT age, (age > 18) as is_adult FROM myapp_person; Person.objects.all().extr ...

  2. cuda9,cuda8分享百度云下载

    一.文件名称: md5-cuda9cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64.debcuda-repo-ubuntu1604-9-0-local_9. ...

  3. 宜人贷蜂巢API网关技术解密之Netty使用实践

    一.背景 宜人贷蜂巢团队,由Michael创立于2013年,通过使用互联网科技手段助力金融生态和谐健康发展.自成立起一直致力于多维度数据闭环平台建设.目前团队规模超过百人,涵盖征信.电商.金融.社交. ...

  4. Centos7安装配置ansible运维自动化工具

    准备至少两台机器 Centos7,这两台机器都关闭 selinux IP:106.13.118.132 服务端(ansible) masterIP:148.70.60.244 节点 slaver 服务 ...

  5. mysql could not be resolved: Name or service not known

    问题: mysql DNS反解:skip-name-resolve 错误日志有类似警告: 1.120119 16:26:04 [Warning] IP address '192.168.1.10' c ...

  6. PHP部分--file图片上传服务器、图片路径存入数据库,并读取

    前端代码 <form action="shangchuan.php" method="post" enctype="multipart/form ...

  7. bb=Discuz与 Discuz! X ,Discuz!NT区别

    没加x的,仅仅是单独的论坛. 加了x的,模块加了很多了,门户,家园,排行榜,群组,都是Discuz! X上的,而Discuz!上没有,所以说Discuz! X更加适用于建设门户网 Discuz! X ...

  8. JQuery ajax 把后台返回的List数据 遍历出来 赋值给div

    1.效果 2.前端代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <he ...

  9. Problem binding to [bigdata-server-01:9000] java.net.BindException: Cannot assign requested address;

    If the port is "0", then the OS is looking for any free port -so the port-in-use and port- ...

  10. Ubuntu Firefox没有声音的解决方案

    安装ubuntu-restricted-extras sudo apt-get install ubuntu-restricted-extras 参考博文:解决ubuntu中firefox没有声音的问 ...