http://acm.hdu.edu.cn/showproblem.php?pid=5040

题意比较难懂,有摄像头的位置是可以走的,每回合开始看做人先走摄像头再转,也就是说如果你这回合走之前没有摄像头在照你,走之后摄像头转过来被照,时间也只是+1,而不是+3(伪装是瞬间完成的)

解法显而易见,一个优先队列的bfs,vis数组多开一维,表示时间对4取模

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <map>
using namespace std ;
int n ;
int vis[][][] ;
int b[][][] ;
char mp[][] ;
int aa,bb ;
struct node
{
int x,y ;
int step ;
friend bool operator <(node aaa,node bbb)
{
return aaa.step>bbb.step ;
}
} ;
int dx[]={-,,,,} ;
int dy[]={,,,-,} ;
int bfs(int x,int y)
{
memset(vis,,sizeof(vis)) ;
priority_queue <node> q ;
node s ;
s.x=x ;s.y=y ;s.step= ;
vis[x][y][]= ;
q.push(s) ;
while(!q.empty())
{
node u=q.top() ;
//printf("%d %d %d\n",u.x,u.y,u.step) ;
if(u.x==aa && u.y==bb)
{
return u.step ;
}
q.pop() ;
for(int i= ;i< ;i++)
{
int xx=u.x+dx[i] ;
int yy=u.y+dy[i] ;
if(xx< || xx>=n || yy< || yy>=n)continue ;
if(mp[xx][yy]=='#')continue ;
node p ;
p=u ;
if(b[xx][yy][u.step%] || b[u.x][u.y][u.step%])
{
if(xx==u.x && yy==u.y && !vis[xx][yy][(u.step+)%])
{
p.step++ ;
vis[xx][yy][p.step%]= ;
q.push(p) ;
}
else if(!vis[xx][yy][(u.step+)%])
{
p.x=xx ;p.y=yy ;
p.step+= ;
vis[xx][yy][p.step%]= ;
q.push(p) ;
}
}
else if(!vis[xx][yy][(u.step+)%])
{
p.x=xx ;p.y=yy ;p.step++ ;
vis[xx][yy][p.step%]= ;
q.push(p) ;
}
}
}
return - ;
}
int main()
{
int T ;
scanf("%d",&T) ;
for(int cas= ;cas<=T ;cas++)
{
scanf("%d",&n) ;
for(int i= ;i<n ;i++)
scanf("%s",mp[i]) ;
int x,y ;
memset(b,,sizeof(b)) ;
for(int i= ;i<n ;i++)
{
for(int j= ;j<n ;j++)
{
if(mp[i][j]=='M')
{
x=i ;y=j ;
}
if(mp[i][j]=='N')
{
b[i][j][]=b[i][j][]=b[i][j][]=b[i][j][]= ;
if(i->=)b[i-][j][]= ;
if(j+<n)b[i][j+][]= ;
if(j->=)b[i][j-][]= ;
if(i+<n)b[i+][j][]= ;
}
if(mp[i][j]=='W')
{
b[i][j][]=b[i][j][]=b[i][j][]=b[i][j][]= ;
if(i->=)b[i-][j][]= ;
if(j+<n)b[i][j+][]= ;
if(j->=)b[i][j-][]= ;
if(i+<n)b[i+][j][]= ;
}
if(mp[i][j]=='S')
{
b[i][j][]=b[i][j][]=b[i][j][]=b[i][j][]= ;
if(i->=)b[i-][j][]= ;
if(j+<n)b[i][j+][]= ;
if(j->=)b[i][j-][]= ;
if(i+<n)b[i+][j][]= ;
}
if(mp[i][j]=='E')
{
b[i][j][]=b[i][j][]=b[i][j][]=b[i][j][]= ;
if(i->=)b[i-][j][]= ;
if(j+<n)b[i][j+][]= ;
if(j->=)b[i][j-][]= ;
if(i+<n)b[i+][j][]= ;
}
if(mp[i][j]=='T')
{
aa=i ;bb=j ;
}
}
}
printf("Case #%d: %d\n",cas,bfs(x,y)) ;
}
return ;
}

HDU 5040的更多相关文章

  1. 2014年北京网络赛 Instrusive HDU 5040 题解 优先队列

    网赛的时候看了这道题,发现就是平常的那种基础搜索题. 由于加了一个特殊条件:可以一次消耗3秒或原地停留1秒. 那就不能使用简单的队列了,需要使用优先队列才行. 题意 告诉一副地图:一个起点,一个终点, ...

  2. hdu 5040 BFS 多维化处理图

    http://acm.hdu.edu.cn/showproblem.php?pid=5040 跟这一题http://blog.csdn.net/u011026968/article/details/3 ...

  3. hdu 5040 bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5040 一个人拿着纸盒子往目的地走  正常情况下一秒走一格  可以原地不动躲在盒子里  也可以套着盒子三秒走一格 ...

  4. hdu 5040 Instrusive【BFS+优先队列】

    11733274 2014-09-26 12:42:31 Accepted 5040 62MS 1592K 4848 B G++ czy 先转一个优先队列的用法: http://www.cppblog ...

  5. HDU 5040 Instrusive(BFS+优先队列)

    题意比较啰嗦. 就是搜索加上一些特殊的条件,比如可以在原地不动,也就是在原地呆一秒,如果有监控也可以花3秒的时间走过去. 这种类型的题目还是比较常见的.以下代码b[i][j][x]表示格子i行j列在x ...

  6. hdu 5040 Instrusive

    Instrusive Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tota ...

  7. leetcode N-Queens/N-Queens II, backtracking, hdu 2553 count N-Queens, dfs 分类: leetcode hdoj 2015-07-09 02:07 102人阅读 评论(0) 收藏

    for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...

  8. HDU 1430 魔板(康托展开+BFS+预处理)

    魔板 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  9. HDU 1043 & POJ 1077 Eight(康托展开+BFS+预处理)

    Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30176   Accepted: 13119   Special ...

随机推荐

  1. Python输出内容的三种方式:print输出 python脚本执行 linux直接执行

    1.  在linux中安装python后,在linux命令行中输入python即可切换到Python命令行下 退出python命令行的命令: 老版本:ctrl+D 新版本:quit();或exit() ...

  2. BZOJ3058 四叶草魔杖

    Poetize11的T3 蒟蒻非常欢脱的写完了费用流,发现...边的cost竟然只算一次!!! 然后就跪了... Orz题解:"类型:Floyd传递闭包+最小生成树+状态压缩动态规划首先Fl ...

  3. BZOJ1584 [Usaco2009 Mar]Cleaning Up 打扫卫生

    令$f[i]$表示以i为结尾的答案最小值,则$f[i] = min \{f[j] + cnt[j + 1][i]^2\}_{1 \leq j < i}$,其中$cnt[j + 1][i]$表示$ ...

  4. tar 排除指定目录 –exclude

    假设 test目录下有 1 2 3 4 5 这5个目录, 1下有6 7两个目录, 现在要将3 4 5 6目录tar打包,2和1下的6这两个目录不要.命令如下: Example[www]#cd test ...

  5. tomcat项目发布 更改小猫图标 及自定义错误404界面

    tomcat发布项目的时候遇到些小问题 不过解决了 问题1. 整个服务器的404自定义界面问题 解决方法: 在tomcat安装目录下conf中web.xml中修改配置文件 <error-page ...

  6. 又一个提示框思密达,腾讯UED

    demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf- ...

  7. Htmlhelper—CheckBox自动生成两个input

    前言 在之前的一篇文章中小猪分享了Htmlhelper的用法.其中有意思的一个就是Checkbox,有必要单独拿出来讲一讲. Htmlhelper—CheckBox 细心的读者一定发现了当使用类似语法 ...

  8. COleDateTime类型的应用

    使用COleDateTime类1) 获取当前时间.      CTime time;      time = CTime::GetCurrentTime();2) 获取时间元素.      int y ...

  9. 0xC0000005: 读取位置 0x00000000 时发生访问冲突

    遇见这种问题一般都是空指针,即:指针里没有赋值~ 如果你对null 进行操作就会产生空指针异常 Object obj = new Object(); 你要知道 obj是一个Object指针变量,指向O ...

  10. hadoop创建两大错误:Bad connection to FS. command aborted. exception和Shutting down NameNod...

    我的hadoop启动后,各个节点都正常,但是无法查看hdfs目录,错误提示 Bad connection to FS. command aborted.  查了下网上的解决办法,主要是删除tmp下的所 ...