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. 爬虫之JSON

    数据提取之JSON与JsonPATH JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写.同时也方便了机器进行解析和生成.适 ...

  2. linux一键安装nginx脚本

    #!/bin/sh echo "----------------------------------start install nginx ------------------------- ...

  3. nagios配置邮件报警

    1.配置sendmail vi /etc/mail.rc 加入以下行 set bsdcompat set from=邮件用户名@domain.com smtp=smtp.126.com set smt ...

  4. idea 快捷键及使用技巧

    IDEA中经常使用的快捷键: Ctrl+Shift + Enter 语句完成 可以快速在行末添加分号,或添加大括号{} Ctrl+Shift + F 全文查找 需要把搜狗打字的快捷键关掉 Ctrl+A ...

  5. python2.7.10 VS2015编译方法

    打开 Python-2.7.10\PCbuild目录 然后设置只编译python和pythoncore: 好了,编译试一试. 出现了好几个错误.由于 VS2015 取消了 timezone 的定义,改 ...

  6. 正确使用iOS常量(const)、enum以及宏(#define)

    前言:本文主要梳理iOS中如何使用常量.enum.宏,以及各自的使用场景. 重要的事情首先说:在iOS开发中请尽量多使用const.enum来代替宏定义(#define):随着项目工程的逐渐增大,过多 ...

  7. Linux shell常用命令

    1. sz 和 rz  sz命令发送文件到本地: # sz filename rz命令本地上传文件到服务器: # rz 执行该命令后,在弹出框中选择要上传的文件即可.

  8. vs2012 在调试或运行的过程中不能加断点

    在使用VS2012 的过程中,突然发现在调试的过程中,不能加断点,显示断点未能绑定.在搜寻了很多解决方案后未能解决,3.23这一天,重装了VS也没有用. 便想着把网上所有的方法都试个遍也要解决这个问题 ...

  9. Linux操作系统简介

    一:Linux系统概述 1.常见操作系统 - 服务端操作系统 : linux.unix.windows server - 单机操作系统 : windows(dos .ucdos.win95.win98 ...

  10. Python flask网站部署总结

    先开一贴,有空来总结下前段时间的网站部署情况.此次部署采用Gunicorn + Nginx + supervisor的组合在VPS环境中部署flask网站应用. Ubuntu环境准备 准备python ...