广搜。

根据题意,可以知道状态总共有$4*n*m$种。每一个位置四种状态:两个都没有发现;发现$E$没发现$D$;发现$D$没发现$E$;两个都发现。

每次移动的花费都是$1$,队列里面状态的费用是单调不减的,所以第一次符合要求的位置就是答案。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} int T,n,m,t;
char s[][];
int sx,sy,ex,ey,dx,dy;
int dir[][]={ {-,},{,},{,-},{,} };
int f[][][];
int dis[][][];
int flag; struct X
{
int a,b,st;
X(int A,int B,int ST)
{
a=A;
b=B;
st=ST;
}
}; bool check(int a,int b)
{
if(a<||a>=n) return ;
if(b<||b>=m) return ;
if(s[a][b]!='.') return ;
return ;
} void bfs()
{
queue<X>Q; int st=f[][sx][sy]*(<<)+f[][sx][sy]*(<<);
Q.push(X(sx,sy,st)); dis[sx][sy][st]=; while(!Q.empty())
{
X h=Q.front(); Q.pop();
if(h.st==)
{
if(dis[h.a][h.b][h.st]<=t)
{
printf("%d\n",dis[h.a][h.b][h.st]);
flag=;
}
return ;
} for(int i=;i<;i++)
{
int tx=h.a+dir[i][],ty=h.b+dir[i][];
if(check(tx,ty)==) continue;
int tst = h.st;
if(f[][tx][ty]==) tst=tst|(<<);
if(f[][tx][ty]==) tst=tst|(<<);
if(dis[tx][ty][tst]!=0x7FFFFFFF) continue; dis[tx][ty][tst]=dis[h.a][h.b][h.st]+;
Q.push(X(tx,ty,tst));
} }
} int main()
{
scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d%d%d",&n,&m,&t);
for(int i=;i<n;i++) scanf("%s",s[i]); for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(s[i][j]=='S') sx=i,sy=j;
if(s[i][j]=='E') ex=i,ey=j;
if(s[i][j]=='D') dx=i,dy=j; for(int k=;k<;k++) dis[i][j][k]=0x7FFFFFFF;
f[][i][j]=f[][i][j]=;
}
} s[sx][sy]='.'; for(int k=;k<=;k++)
{
int a,b;
for(int i=;i<;i++)
{
if(k==) a=ex,b=ey;
else a=dx,b=dy;
for(int j=;;j++)
{
a=a+dir[i][], b=b+dir[i][];
if(check(a,b)==) break;
f[k][a][b]=;
}
}
} printf("Case %d:\n",cas++);
flag=; bfs();
if(flag==) printf("-1\n");
}
return ;
}

HDU 4528 小明系列故事――捉迷藏的更多相关文章

  1. HDU 4828 小明系列故事——捉迷藏

    漂亮妹子点击就送:http://acm.hdu.edu.cn/showproblem.php?pid=4528 Time Limit: 500/200 MS (Java/Others)    Memo ...

  2. HDU 4528 BFS 小明系列故事——捉迷藏

    原题直通车:HDU 4528 小明系列故事——捉迷藏 分析: 标记时加两种状态就行. 代码: #include<iostream> #include<cstring> #inc ...

  3. C - 小明系列故事――捉迷藏 HDU - 4528 bfs +状压 旅游-- 最短路+状压

    C - 小明系列故事――捉迷藏 HDU - 4528 这个题目看了一下题解,感觉没有很难,应该是可以自己敲出来的,感觉自己好蠢... 这个是一个bfs 用bfs就很好写了,首先可以预处理出大明和二明能 ...

  4. hdu 4506 小明系列故事——师兄帮帮忙【幂取模乱搞】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4506 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  5. hdu 4542 小明系列故事——未知剩余系

    小明系列故事——未知剩余系 题意:操作0表示某数有n个约数,操作1为某数有n个非约数:n <= 47777,若是存在小于2^62的数符合,则输出该数,否则若是不存在输出Illegal,若是大于2 ...

  6. HDU 4511 小明系列故事——女友的考验 (AC自动机+DP)

    小明系列故事——女友的考验 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  7. HDU 4511 小明系列故事——女友的考验 (AC自动机 + DP)

    小明系列故事——女友的考验 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  8. hdu 4542 小明系列故事——未知剩余系 反素数 + 打表

    小明系列故事——未知剩余系 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Prob ...

  9. hdu4528 小明系列故事——捉迷藏

    Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s ...

随机推荐

  1. line-height用法总结

    Line-height是前端用语,经常被前端开发人员经常使用. line-height设置1.5和150%有什么区别?这是一个比较常见的前端面试题. 定义: line-height指的是文本行基线间的 ...

  2. Netscaler重置密码的方法

    Netscaler重置密码的方法 http://blog.51cto.com/caojin/1898401 有时候我们会碰到忘记Netscaler的密码,或接手别人的设备而不知道密码的情况.在这种情况 ...

  3. [Leetcode] String to integer atoi 字符串转换成整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  4. axios超时重发

    axios的超时是在response中处理的,所以要在response中添加拦截器: axios.interceptors.response.use(undefined, function axios ...

  5. angular js的Inline Array Annotation的理解

    inline Array annotation的形式是: someModule.controller('MyController', ['$scope', 'greeter', function($s ...

  6. pycharm激活(JetBrains IDEA 系列产品通用xx方法(license server))

    http://xclient.info/a/f0b9738a-36fd-8a97-a966-0d3db497092d.html .打开激活窗口 .选择 Activate new license wit ...

  7. Eclipse CDT 调用printf/cout 控制台(console)无输出

    转摘自:http://blog.csdn.net/dj0379/article/details/6940836 症状描述: 用Eclipse调试程序,执行printf和cout函数,但是console ...

  8. python的tuple()

    描述 Python 元组 tuple() 函数将列表转换为元组. 语法 tuple()方法语法: tuple( seq ) 参数 seq -- 要转换为元组的序列. 返回值 返回元组. 实例 以下实例 ...

  9. Linux : 从私钥中提取公钥

    已知一个私钥, 如何从其中提取公钥出来? 提取公钥 ssh-keygen -y -f /path/to/private_key > /path/to/public_key

  10. USACO月赛2005 january volume

    2013-09-18 08:12 由题可知,ans=∑i  ∑j(x[i]-x[j]) 最后整理完之后应该是不同系数的X[i]相加,所以这道题就成了求不同x[i]的系数 对于X[i],它需要减前面(i ...