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的更多相关文章

  1. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  2. hdu 3345 War Chess

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

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

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Kafka架构

    一.Kafka介绍 Kafka是Linkin在2010年开源的分布式发布订阅消息系统,Kafka是高吞吐量的消息订阅系统. 二.Kafka结构 Kafka由三部分构成,producer.broker. ...

  2. prometheus statsd 监控

    Prometheus是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采用Prometheus,社会也十分活跃,他们 ...

  3. LeetCode——remove-duplicates-from-sorted-list-ii

    Question Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only dist ...

  4. AJAX的例子

    var XMLHttpReq; //根据不同的浏览器创建不同的XMLHttpRequest对象function createXMLHttpRequest() {  if (window.XMLHttp ...

  5. Fedora安装opengl

    Fedora和Ubuntu下安装OpenGL开发环境配置(我整理的)OpenGL开发库的详细介绍fedora23 安装OpenGL 开发OpenGL工程需要3个库文件和对应的头文件:libglut.s ...

  6. 关于Spring中applicationContext.xml配置错误“org/springframework/transaction/interceptor/TransactionInterceptor”的问题解决

    问题描述: 在配置spring的applicationContext.xml中的默认事务管理器的时候可能会出现这样的错误: Error occured processing XML 'org/spri ...

  7. ZooKeeper原理 --------这可能是把ZooKeeper概念讲的最清楚的一篇文章

    相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么,你能回答到哪个地步呢? 我本人曾经使用过 ZooKee ...

  8. 三十一 Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter

    1.chrome谷歌浏览器无界面运行 chrome谷歌浏览器无界面运行,主要运行在Linux系统,windows系统下不支持 chrome谷歌浏览器无界面运行需要一个模块,pyvirtualdispl ...

  9. 在接口请求时报错Unrecognized field &quot;zZF1&quot

    这个问题是json序列化问题,当参数中出现大写字母组成的字段时(例如:ZZF1),此时需在字段上加入注解:@JsonProperty(value = "ZZF1")

  10. CentOS7 LVM添加硬盘及扩容

    一.LVM简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制.LVM将一个或多个磁盘分区(PV)虚拟为一个卷组(VG), ...