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. was7 安装遇到问题(Linux平台Redhat 6)

    1../launchpad.sh 无法启动安装,提示无法找到浏览器 解决:直接进入WAS文件夹,执行install cd WAS ./install 2.安装时中文乱码 设置区域为美国: LANG=e ...

  2. C#入门篇6-6:字符串操作 StringBiulder string char[]之间的转化

    //StringBiulder string char[]之间的转化 public static void Fun3() { StringBuilder sb = new StringBuilder( ...

  3. python 爬虫

    import urllib2 as url import re urls = 'http://www.php100.com/html/it/' headers = {'User-Agent':'Moz ...

  4. UVALive 5905 Pool Construction 最小割,s-t割性质 难度:3

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  5. Jquery判断div是否显示

    $("#test").is(":hidden");//是否隐藏 $("#test").is(":visible");// ...

  6. 安装svnx2出现 Make sure an svn tool (≥ v1.6) is present in the folder: “/usr/bin”

    安装svnx2出现 Make sure an svn tool (≥ v1.6) is present in the folder: “/usr/bin” 是因为svnx2需要用到svn的地址,修改为 ...

  7. [vijos P1023] Victoria的舞会3

    这… 本来想学习一下Tarjan算法的,没想到码都码好了发现这题不是求强连通分量而是简单的连通分量…图论基础都还给老师了啊啊啊!最后深搜通通解决! v标记是否被访问过,scc标记每个的祖先(本来想写T ...

  8. 基于K2 BPM平台,中原地产实现了从2个人到5万多人的跨越

    演讲人:吴付文 中原地产CIO 点击这里查看中原地产怎么使用BPM实现业绩的飞跃式发展.

  9. jQuery Ajax之load()方法

    jQuery对Ajax操作进行了封装,在jQuery中$.ajax()方法属于最底层的方法,第2层是load().$.get()和$.post()方法,第3层是$.getScript()和$.getJ ...

  10. 记录一些容易忘记的属性 -- UILabel

    一:UILabel lbl.alpha=0.f;    lbl 透明,会影响子视图的显示 lbl.backgroundColor=[UIColor clearColor]; lbl 背景色透明,子视图 ...