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 ...
随机推荐
- 51nod 1851俄罗斯方块(trick)
题目大意:给出一个黑白图,你可以选定一个俄罗斯方块的区域,黑白翻转,问能否变成白图 比较trick的题目, 首先可以想到,奇数个1肯定是无解的,所以考虑偶数个1 可以先讨论n是2的情况 当n为2时,其 ...
- redux-saga基本用法
redux-saga是管理redux异步操作的中间件,redux-saga通过创建sagas将所有异步操作逻辑收集在一个地方集中处理. sagas采用Generator函数来yield Effects ...
- bzoj2348
实在不懂为啥网上的题解都是二分,本人没写二分,wa的很惨结果竟然是printf("%d")的锅,改了就A了 2348: [Baltic 2011]Plagiarism Time L ...
- 【BZOJ 4514】[Sdoi2016]数字配对 费用流
利用spfa流的性质,我直接拆两半,正解分奇偶(妙),而且判断是否整除且质数我用的是暴力根号,整洁判断质数个数差一(其他非spfa流怎么做?) #include <cstdio> #inc ...
- mysql5.7.22以上版本忘记密码时这样修改
1.关闭mysql服务 net stop mysql 2.找到mysql安装路径找到 my.ini 打开在 [mysqld] 下添加 skip-grant-tables 跳过密码校验 3.登陆mysq ...
- Fabric证书解析
一.证书目录解析 通过cryptogen生成所有证书文件后,以peerOrgannizations的第一个组织树org1为例,每个目录和对应文件的功能如下: ca: 存放组织的根证书和对应的私 ...
- ansible 批量修改root密码
[root@sz_fy_virt_encrypt_33_239 fetch]# cat /opt/passwd.yml - hosts: web vars: path: /home/opsadmin ...
- BAT定期删除N天前的文件
1.直接看脚本在win2008测试可用 ::clean logs @echo off title clean up logs ::delete logs FORFILES /P /C "cm ...
- 普通table表格样式及代码大全
普通table表格样式及代码大全(全)(一) 单实线边框表格 <table style="border-collapse: collapse" borderColor=#0 ...
- 正式进入搭建OpenStack
部署mariadb数据库 控制节点: yum install mariadb mariadb-server python2-PyMySQL -y 编辑: /etc/my.cnf.d/openstack ...