HDU 4528 小明系列故事――捉迷藏
广搜。
根据题意,可以知道状态总共有$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 小明系列故事――捉迷藏的更多相关文章
- HDU 4828 小明系列故事——捉迷藏
漂亮妹子点击就送:http://acm.hdu.edu.cn/showproblem.php?pid=4528 Time Limit: 500/200 MS (Java/Others) Memo ...
- HDU 4528 BFS 小明系列故事——捉迷藏
原题直通车:HDU 4528 小明系列故事——捉迷藏 分析: 标记时加两种状态就行. 代码: #include<iostream> #include<cstring> #inc ...
- C - 小明系列故事――捉迷藏 HDU - 4528 bfs +状压 旅游-- 最短路+状压
C - 小明系列故事――捉迷藏 HDU - 4528 这个题目看了一下题解,感觉没有很难,应该是可以自己敲出来的,感觉自己好蠢... 这个是一个bfs 用bfs就很好写了,首先可以预处理出大明和二明能 ...
- hdu 4506 小明系列故事——师兄帮帮忙【幂取模乱搞】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4506 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- hdu 4542 小明系列故事——未知剩余系
小明系列故事——未知剩余系 题意:操作0表示某数有n个约数,操作1为某数有n个非约数:n <= 47777,若是存在小于2^62的数符合,则输出该数,否则若是不存在输出Illegal,若是大于2 ...
- HDU 4511 小明系列故事——女友的考验 (AC自动机+DP)
小明系列故事——女友的考验 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- HDU 4511 小明系列故事——女友的考验 (AC自动机 + DP)
小明系列故事——女友的考验 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- hdu 4542 小明系列故事——未知剩余系 反素数 + 打表
小明系列故事——未知剩余系 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Prob ...
- hdu4528 小明系列故事——捉迷藏
Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s ...
随机推荐
- BZOJ4557 JLOI2016侦察守卫(树形dp)
下称放置守卫的点为监控点.设f[i][j]为i子树中深度最大的未被监视点与i的距离不超过j时的最小代价,g[i][j]为i子树中距离i最近的监控点与i的距离不超过j且i子树内点全部被监视时的最小代价. ...
- SPOJ Distinct Substrings(后缀数组求不同子串个数,好题)
DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its dist ...
- [Leetcode] Symmetric tree 对称二叉树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- POJ2516:Minimum Cost(最小费用最大流)
Minimum Cost Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 19088 Accepted: 6740 题目链 ...
- eclipse关闭错误警告提示
- HDU2553 N皇后问题---(dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2553 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在 ...
- 【spoj1811 & spoj1812 - LCS1 & LCS2】sam
spoj1811 给两个长度小于100000的字符串 A 和 B,求出他们的最长公共连续子串. 先将串 A 构造为 SAM ,然后用 B 按如下规则去跑自动机.用一个变量 lcs 记录当前的最长公共 ...
- 25个常规方法优化你的jquery代码
原文发布时间为:2011-06-06 -- 来源于本人的百度文章 [由搬家工具导入] http://www.tvidesign.co.uk/blog/improve-your-jquery-25-ex ...
- android 调试 native 程序的方法
一.背景 首先说需求,这个需求非常常见,就是android上需要的一个功能,linux已经有开源代码而且非常稳定,希望能直接porting过去使用,这个程序是pure c 的代码,也就是说,跟andr ...
- 智联招聘的python岗位数据词云制作
# 根据传入的背景图片路径和词频字典.字体文件,生成指定名称的词云图片 def generate_word_cloud(img_bg_path, top_words_with_freq, font_p ...