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 ...
随机推荐
- MR案例:路径过滤PathFilter
问题描述:现有一批cookie日志,按照日期进行存放,如目录 “dir/2015-08-08” 下存放2015-08-08这一天的所有cookie.而目录 “/2015-08-08/” 下又根据数据文 ...
- shell小脚本--从laod博客更新hosts文件
#!/bin/bash #-------------------------------------------- # name: change-hosts.sh #----------------- ...
- Mysql binlog设置
一:Binlog文件信息 1. binlog基本定义:二进制日志,也成为二进制日志,记录对数据发生或潜在发生更改的SQL语句,并以二进制的形式保存在磁盘中: 2. 作用:MySQL的作用类似于Ora ...
- Secure a Web API with Individual Accounts and Local Login in ASP.NET Web API 2.2
https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/individual-accounts-in-web-api Ind ...
- AngularJS Injector和Service的工作机制
要了解angularJS里的injector和Service是如何工作的,需要阅读/src/auto/injector.js.另外要结合/src/loader.js才能明白它的应用场景. auto/i ...
- 如何在repeater中找到checkbox并实现全选删除
checkbox使用客户端控件,且给repeater里边的checkbox添加ruanat=server属性表头中的chkTotal的属性一定不要加此属性....然后 全选的javascript代码 ...
- Pandas 数据分析基础
Pandas 安装 anaconda 安装: conda list pandas 查看是否已经安装 conda install pandas conda update pandas pip 安装 pi ...
- 关于IIS权限问题(Selenium WebDriver调用出错记录)
本地VS调试过程中用Selenium WebDriver打开FF浏览器可以正常工作,项目部署至IIS后请求调用浏览器一直提示超时,异常如下: 因为本地调试可以成功,首先排除组件版本问题和浏览器兼容问题 ...
- MySQL安装的N种方式
一.二进制包安装 1.)下载:在官网的下载页面下的服务器操作系统选择 Linux- Generic : 进制分发版的格式是:mysql-<版本>-<OS>-tar.gz 2. ...
- js打乱数组的实战应用
文章首发于: https://www.xiabingbao.com/post/javascript/js-random-array.html 在js中,能把数组随机打乱的方法有很多,每个方法都有自己的 ...