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 ;
}

最新文章

  1. Android开发学习之路-LeakCanary使用
  2. apche启动错误|httpd.pid overwritten — Unclean shutdown of previous Apache run?
  3. 这算是ASP.NET MVC的一个大BUG吗?
  4. VC 使用OnCtlColor函数来改变控件颜色(引用)
  5. Java Attach API
  6. DB2 UDB DBA 核对清单
  7. 【锁】Oracle锁系列
  8. 安装postgreSQL出现configure:error:readline library not found解决方法
  9. Library Cache Lookup
  10. ListView嵌套ListView时发生:View too large to fit into drawing cache的问题
  11. iOS 纯代码适配iPhone6,6+
  12. tomcat改端口的一些问题
  13. Html5笔记之第六天
  14. android 基础02 - Activity 的生命周期及状态
  15. .Net Core应用框架Util介绍(五)
  16. dos4章
  17. 【转】Windows Server 2008 R2下安装 .net framework3.5
  18. Alpha(2/10)
  19. Java中CountDownLatch和CyclicBarrier
  20. Devexpress Gridview 自定义汇总CustomSummaryCalculate(加权平均)

热门文章

  1. 在唯一密钥属性“name”设置为“ScriptHandlerFactory”时,无法添加类型为“add”的重复集合项
  2. Java 集合系列 17 TreeSet
  3. Java 集合系列 02 Collection架构
  4. R-Studio
  5. 学习记录014-ssh批量分发
  6. Xmanager如何连接图形化界面
  7. bzoj 1821: [JSOI2010]Group 部落划分 Group
  8. [Elasticsearch] 多字段搜索 (三) - multi_match查询和多数字段 &lt;译&gt;
  9. 给出一个长度为n的数列,请对于每一个数,输出他右边第一个比他大的数。n&lt;=100000.
  10. 前端必须掌握30个CSS3选择器