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 ...
随机推荐
- yield生成器函数
生成器有主要有四种方法: next() 执行函数,直到遇到下一个yield为止,并返回值 send(value) 为生成器发送一个数值,next()方法就相当于send(None) close() 终 ...
- 再也不学AJAX了!(一)AJAX概述
"再也不学AJAX了"是一个与AJAX主题相关的文章系列,包含以下三个部分的内容: AJAX概述:主要回答"AJAX是什么"这个问题: 使用AJAX:介绍如何通 ...
- 何为K-邻近算法
答:K-邻近算法,英文为K-nearest neighbor(KNN),就是计算要测试对象与k个样本对象之间的距离,通过距离的大小来对测试对象进行分类
- [BZOJ4003]城池攻占
Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖, ...
- Forcing restore from package sources
https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore#forcing-restore-from-package ...
- [Network Architecture]ResNext论文笔记(转)
文章地址: https://blog.csdn.net/u014380165/article/details/71667916 论文:Aggregated Residual Transformatio ...
- DataReader 连接数据库完整过程和代码(Sql Server)
数据库名叫:Bu 有个表:A 里面有一列:ID 需要引用 using System.Data.SqlClient; 代码部分如下: SqlConnection sqlCon=new SqlConnec ...
- HtmlAgilityPach基本使用方法
//过滤html标签 static void InnerText() { HtmlWeb htmlWeb = new HtmlWeb(); HtmlDocument doc = htmlWeb.Loa ...
- 设计模式--门面模式C++实现
门面模式C++实现 1定义facade 要求一个子系统的外部接口与其内部的通信必须通过一个统一的接口进行.门面模式提供一个高层次的接口,使得子系统更容易视同 注:门面模式注重统一对象,也就是提供一个访 ...
- 转 Java对日期Date类进行加减运算一二三
请移步,https://blog.csdn.net/hacker_lees/article/details/74351838 ,感谢博主分享