hdu 1429 bfs+状压
题意:这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方。刚开始 Ignatius被关在(sx,sy)的位置,离开地牢的门在(ex,ey)的位置。Ignatius每分钟只能从一个坐标走到相邻四个坐标中的其中一 个。魔王每t分钟回地牢视察一次,若发现Ignatius不在原位置便把他拎回去。经过若干次的尝试,Ignatius已画出整个地牢的地图。现在请你帮 他计算能否再次成功逃亡。只要在魔王下次视察之前走到出口就算离开地牢,如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败。
每组测试数据的第一行有三个整数n,m,t(2<=n,m<=20,t>0)。接下来的n行m列为地牢的地图,其中包括:
. 代表路
* 代表墙
@ 代表Ignatius的起始位置
^ 代表地牢的出口
A-J 代表带锁的门,对应的钥匙分别为a-j
a-j 代表钥匙,对应的门分别为A-J
记得去年网赛有这样一题,当时不会状压,搞不出来,现在看起来还是很水的
得到钥匙的状态用二进制表示,比如有A钥匙即为1,有A,C钥匙即为101
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int vis[][][];
char s[][];
int d[][]={,,,,-,,,-};
int n,m,tt,time;
struct node
{
int x,y,t,key;
node(){}
node(int xx,int yy,int tt,int kk)
{
x=xx,y=yy,t=tt,key=kk;
}
}st,ed;
void bfs()
{
node now,next;
queue<node> q;
q.push(node(st.x,st.y,,));
vis[st.x][st.y][]=;
while(!q.empty())
{
now=q.front();
q.pop();
if(now.x==ed.x&&now.y==ed.y)
{
if(now.t<time)
{
printf("%d\n",now.t);
return;
}
else
break;
}
for(int i=;i<;i++)
{
next.x=now.x+d[i][];
next.y=now.y+d[i][];
next.t=now.t+;
next.key=now.key;
if(next.x>=&&next.y>=&&next.x<n&&next.y<m&&s[next.x][next.y]!='*')
{
if('A'<=s[next.x][next.y]&&s[next.x][next.y]<='J')
{
int key=<<(s[next.x][next.y]-'A');
if((next.key&key)&&!vis[next.x][next.y][next.key])
{
vis[next.x][next.y][next.key]=;
q.push(next);
}
}
else if(s[next.x][next.y]>='a'&&s[next.x][next.y]<='j')
{
int key=(<<(s[next.x][next.y]-'a'));
next.key=(next.key|key);
if(!vis[next.x][next.y][next.key])
{
vis[next.x][next.y][next.key]=;
q.push(next);
}
}
else
{
if(!vis[next.x][next.y][next.key])
{
vis[next.x][next.y][next.key]=;
q.push(next);
}
}
}
}
}
printf("-1\n"); }
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d%d%d",&n,&m,&time)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%s",s[i]);
for(j=;j<m;j++)
{
if(s[i][j]=='@') st.x=i,st.y=j;
if(s[i][j]=='^') ed.x=i,ed.y=j;
}
}
memset(vis,,sizeof(vis));
bfs();
}
}
hdu 1429 bfs+状压的更多相关文章
- hdu 2209 bfs+状压
http://acm.hdu.edu.cn/showproblem.php?pid=2209 不知为啥有种直觉.会出状压+搜索的题,刷几道先 简单的BFS.状压表示牌的状态, //#pragma co ...
- hdu 5025 bfs+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...
- HDU 4771 BFS + 状压
Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- C - 小明系列故事――捉迷藏 HDU - 4528 bfs +状压 旅游-- 最短路+状压
C - 小明系列故事――捉迷藏 HDU - 4528 这个题目看了一下题解,感觉没有很难,应该是可以自己敲出来的,感觉自己好蠢... 这个是一个bfs 用bfs就很好写了,首先可以预处理出大明和二明能 ...
- hdu 1044(bfs+状压)
非常经典的一类题型 没有多个出口.这里题目没有说清楚 Collect More Jewels Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 5094 Maze (BFS+状压)
题意: n*m的迷宫.多多要从(1,1)到达(n,m).每移动一步消耗1秒.有P种钥匙. 有K个门或墙.给出K个信息:x1,y1,x2,y2,gi 含义是(x1,y1)与(x2,y2)之间有gi ...
- hdu 4771 Stealing Harry Potter's Precious (BFS+状压)
题意: n*m的迷宫,有一些格能走("."),有一些格不能走("#").起始点为"@". 有K个物体.(K<=4),每个物体都是放在& ...
- 孤岛营救问题 (BFS+状压)
https://loj.ac/problem/6121 BFS + 状压 写过就好想,注意细节debug #include <bits/stdc++.h> #define read rea ...
- HDU 5025:Saving Tang Monk(BFS + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description <Journey to ...
随机推荐
- numpy之ones,array,asarray
from:http://blog.csdn.net/gobsd/article/details/56485177 numpy.ones() 废话少说直接上代码 >>> np.ones ...
- 高级C#信使(译) - Unity维基百科
高级C#信使 作者:Ilya Suzdalnitski 译自:http://wiki.unity3d.com/index.php/Advanced_CSharp_Messenger 描述 前言 Mis ...
- 在Mac上搭建ReactNative开发环境
1.安装Homebrew, Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件. /usr/bin/ruby -e "$(curl -fsSL https://raw.g ...
- Python 模块进阶
import导入模块 1. import 搜索路径 import sys sys.path 例子: In [1]: import sys In [2]: sys.path Out[2]: ['', ' ...
- (六)MyBatis杂项
第一节:处理CLOB.BLOB类型数据 第二节:传入多个输入参数 第三节:MyBatis分页 1,逻辑分页 2,物理分页 MyBatis默认情况下,MyBatis启用一级缓存,即同一个SqlSessi ...
- ubuntu和windows双系统启动顺序的修改
ubuntu和windows双系统启动顺序的修改 说到启动就不得不说GRUB,Linux下大名鼎鼎的启动管理工具(曾经的LILO已经风光不再),当然现在已经是GRUB2了,GRUB2和GRUB最重要的 ...
- oracle创建job和删除job
https://blog.csdn.net/u010001043/article/details/56479774
- HBase应用之微博案例
一. 需求分析 1) 微博内容的浏览,数据库表设计 2) 用户社交体现:关注用户,取关用户 3) 拉取关注的人的微博内容 二. 代码实现 代码设计总览: 1.创建命名空间以及表名的定义 //获取配置 ...
- Spark(十四)SparkStreaming的官方文档
一.SparkCore.SparkSQL和SparkStreaming的类似之处 二.SparkStreaming的运行流程 2.1 图解说明 2.2 文字解说 1.我们在集群中的其中一台机器上提交我 ...
- Linux 中 &、jobs、fg、bg 等命令
参考 Unix 或 Linux 中 &.jobs.fg.bg 等命令的使用方法 对之前文章的一个补充: linux 命令后台运行 这篇还是比较简单的,稍微一带而过 fg.bg.jobs.&a ...