HDU 3345
http://acm.hdu.edu.cn/showproblem.php?pid=3345
最近重写usaco压力好大,每天写的都想吐。。
水一道bfs
注意的是开始旁边有敌人可以随便走,但是一旦开始走,再与敌人相邻行动力就变为0
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std ;
char map[][] ;
char ans[][] ;
int vis[][] ;
int n,m,MV ;
typedef struct L{
int x,y ;
int mv ;
friend bool operator <(L a,L b)
{
return a.mv<b.mv ;
}
}L ;
L s ;
int dir[][]={,,,,,-,-,} ;
int ok(int x,int y)
{
for(int i= ;i< ;i++)
{
int xx=x+dir[i][] ;
int yy=y+dir[i][] ;
if(xx< || yy< || xx>=n || yy>=m)continue ;
if(map[xx][yy]=='E')
return ;
}
return ;
}
void bfs()
{
priority_queue <L> q ;
L now,next ;
memset(vis,,sizeof(vis)) ;
q.push(s) ;
vis[s.x][s.y]= ;
while(!q.empty())
{
now=q.top() ;
for(int i= ;i< ;i++)
{
int xx=now.x+dir[i][] ;
int yy=now.y+dir[i][] ;
if(xx< || yy< || xx>=n || yy>=m)continue ;
if(vis[xx][yy])continue ;
if(map[xx][yy]=='#')continue ;
if(map[xx][yy]=='E')continue ;
next.x=xx ;next.y=yy ;
if(map[xx][yy]=='.' && now.mv>=)
{
next.mv=now.mv- ;
if(ok(xx,yy))
next.mv= ;
vis[xx][yy]= ;
ans[xx][yy]='*' ;
q.push(next) ;
}
if(map[xx][yy]=='T' && now.mv>=)
{
next.mv=now.mv- ;
if(ok(xx,yy))
next.mv= ;
vis[xx][yy]= ;
ans[xx][yy]='*' ;
q.push(next) ;
}
if(map[xx][yy]=='R' && now.mv>=)
{
next.mv=now.mv- ; if(ok(xx,yy))
next.mv= ;
vis[xx][yy]= ;
ans[xx][yy]='*' ;
q.push(next) ;
}
if(map[xx][yy]=='P' && now.mv>=)
{
next.mv=now.mv- ;
if(ok(xx,yy))
next.mv= ;
vis[xx][yy]= ;
q.push(next) ;
}
}
q.pop() ;
}
}
int main()
{
int t ;
scanf("%d",&t) ;
while(t--)
{
scanf("%d%d%d",&n,&m,&MV) ;
for(int i= ;i<n ;i++)
scanf("%s",map[i]) ;
for(int i= ;i<n ;i++)
{
for(int j= ;j<m ;j++)
{
ans[i][j]=map[i][j] ;
if(map[i][j]=='Y')
s.x=i,s.y=j,s.mv=MV ;
}
}
bfs() ;
for(int i= ;i<n ;i++)
{
for(int j= ;j<m ;j++)
{
printf("%c",ans[i][j]) ;
}
putchar('\n') ;
}
putchar('\n') ;
}
return ;
}
HDU 3345的更多相关文章
- War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...
- hdu 3345 War Chess
War Chess Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 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 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 彻底搞懂hashCode与equals的作用与区别及应当注意的细节
以前写程序一直没有注意hashCode的作用,一般都是覆盖了equals,缺没有覆盖hashCode,现在发现这是埋下了很多潜在的Bug!今天就来说一说hashCode和equals的作用. 先来试想 ...
- log4j2按日志级别输出到指定文件
在项目中,可能会产生非常多的日志记录,为了方便日志分析,一般可以将日志按级别输出到指定文件,本次就先说说log4j2的实现吧: 1.先加入log4j2依赖包 2.写一个java类进行测试,类文件中仅仅 ...
- tomcat配置根目录访问后,部署后第一次访问会出现tomcat的默认界面而非项目首页
tomcat配置根目录访问后,部署后第一次访问会出现tomcat的默认界面而非项目首页,而重启后会正常,这个原因是因为在配置文件中有如下配置,造成项目加载两次 <Host name=" ...
- NOIP2014 T4 子矩阵 dfs+dp
最近在狂补题啊QAQ... 打算先把NOIP的干掉吧... 点我看题 链接还是放洛谷的了... 题意:给一个n*m的矩阵,在这个矩阵里选 r 行 c 列,然后这 r 行 c 列所相交的格子为新矩阵的, ...
- angular js实现开关效果
功能:实现点击排序,再点击排倒序. 实现方法如下 方法一:定义变量实现点击切换true或false,代码为: $scope.lidata = [ {"name ...
- [BZOJ3244][NOI2013]树的计数
这题大家为什么都写O(NlogN)的算法呢?…… 让本蒟蒻来写一个O(N)的吧…… 首先还是对BFS序和DFS序重编号,记标好的DFS序为d[1..n].令pos[x]为x在d[]中出现的位置,即po ...
- Spring MVC 方法注解拦截器
应用场景,在方法级别对本次调用进行鉴权,如api接口中有个用户唯一标示accessToken,对于有accessToken的每次请求可以在方法加一个拦截器,获得本次请求的用户,存放到request或者 ...
- Delphi.format填充0
1. ]);// 一共8位数字不够的补零 2. 3. 4. 5.
- 实现Runnable和继承Thread的区别
啥都先不说,运行两段程序看看结果再分析 实现Runnable接口的程序代码 public class ThreadTest1 implements Runnable { private int num ...
- JAVA8新特性简单总结
速度更快代码更少强大的StreamAPI便于并行最大化的减少空指针异常Lambda表达式<具体做什么事>和函数式接口Lambda表达式(也叫做闭包)它允许我们将一个函数当作方法的参数(传递 ...