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 ...
随机推荐
- Socket常见错误代码与描述
最近程序 出现 几次 Socket 错误, 为了便于 差错.. 搜了一些 贴在这里.. 出现网络联机错误Socket error #11001表示您的计算机无法连上服务器,请检查您的Proxy设定以及 ...
- Java Web开发之路(一)——环境配置
1. 下载JDK(Java Development Kit)工具包.其中包括运行Java程序所必须的JRE环境及开发过程中常用的库文件. (JDK与JRE的关系: JDK是Java的开发环境,在编写J ...
- 【题解】Bzoj2560串珠子
挺强的……容斥+状压DP.首先想到如果可以求出f[k],f[k]代表联通状态为k的情况下的合法方案数,则f[k] = g[k] - 非法方案数.g[k]为总的方案数,这是容易求得的.那么非法方案数我们 ...
- 使用def文件简化dll导出
原文链接地址:http://www.cnblogs.com/TianFang/archive/2013/05/04/3059073.html 在C++中,我们可以通过 __declspec(dllex ...
- 洛谷 P2529 [SHOI2001]击鼓传花 解题报告
P2529 [SHOI2001]击鼓传花 题意:求出\(n!\)末尾最后一位非0数字 数据范围:\(n<=10^{100}\) 我们从简单的开始考虑 1.显然,\(n!\)可以被这么表示 \(n ...
- dva的基本用法
dva是一个状态管理工具,整合了redux,redux-saga,react-router,fetch等框架,目前只能用于react的状态管理 1. dva的models dva的主要作用还是整合了r ...
- HDU3038:How Many Answers Are Wrong(带权并查集)
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- elk,centos7,filebeat,elasticsearch-head详细安装步骤
先来张图,大致结构应该晓得,对吧! 安装jdk:至少1.8以上 yum -y localinstall jdk-8u73-linux-x64.rpm 安装elasticsearch5.2.1 用普通用 ...
- vue2学习篇一 $mount()手动挂载
$mount()手动挂载 //当Vue实例没有el属性时,则该实例尚没有挂载到某个dom中: //假如需要延迟挂载,可以在之后手动调用vm.$mount()方法来挂载.例如: new Vue({ // ...
- lhgdialog的传值问题
一前言 今天就离职了,顺便把还没有记载下来得Js有关知识给记载下来,其实这个是lhgdialog.js中的传值问题.就是弹出框选择数据后加载到父页面上,自己用html做了测试. 二:内容 html代码 ...