hdu 5094 状压bfs+深坑
http://acm.hdu.edu.cn/showproblem.php?pid=5094
给出n*m矩阵
给出k个障碍,两坐标之间存在墙或门,门最多10种,状压可搞
给出s个钥匙位置及编号,相应的钥匙开相应的门,求从1,1到n,m的最短时间,不能到底则输出-1
这里有一个大坑:有可能同一个位置有多个门或者多个钥匙...
这么坑大丈夫?
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int inf = 0x3fffffff;
const LL _inf = 1e18;
const int maxn = 55,maxm = 1<<12;
int n,m,p;
bool vis[maxn][maxn][maxm];
int g[maxn][maxn][maxn][maxn],key[maxn][maxn];//0up1down2left3right
int b[12];
struct node{
int x,y,st,t;
node(){};
node(int xx,int yy,int _st,int tt):x(xx),y(yy),st(_st),t(tt){};
bool operator < (const node &a)const{
return a.t < t;
}
};
int dx[] = {0,0,-1,1},
dy[] = {-1,1,0,0};
bool in(int x,int y)
{
return 1 <= x && x<=n && 1 <= y && y <= m;
}
void bfs()
{
priority_queue<node> q;
q.push(node(1,1,key[1][1],0));
vis[1][1][key[1][1]] = 1; while(!q.empty()){
node cur = q.top();
q.pop();
if(cur.x == n && cur.y == m){
//cout<<cur.x<<','<<cur.y<<':';
printf("%d\n",cur.t);
return;
}
int x = cur.x,y = cur.y,t = cur.t,st = cur.st;
//cout<<x<<'.'<<y<<':'<<t<<endl;
for(int i = 0;i < 4;++i){
int tx = x + dx[i],ty = y + dy[i];
if(!in(tx,ty) || g[x][y][tx][ty] & 1 == 1)continue;
if(g[x][y][tx][ty] && !(st & g[x][y][tx][ty]))continue;
int _st = st | key[tx][ty];
if(!vis[tx][ty][_st]){
vis[tx][ty][_st] = 1;
q.push(node(tx,ty,_st,t+1));
}
}
}
puts("-1");
}
void init()
{
for(int i = 0;i < 12;++i)
b[i] = 1<<i;
}
void work()
{
clr0(vis),clr0(key);
clr0(g);
int k,s,x,y,q,x1,y1,x2,y2,st;
RD(k);
while(k--){
RD2(x1,y1),RD3(x2,y2,st);
g[x1][y1][x2][y2] |= b[st];
g[x2][y2][x1][y1] |= b[st];
}
RD(s);
while(s--){
RD3(x,y,q);
key[x][y] |= b[q];
}
bfs();
return ;
}
int main()
{
init();
while(~RD3(n,m,p)){
work();
}
return 0;
}
hdu 5094 状压bfs+深坑的更多相关文章
- hdu 4845 状压bfs(分层思想)
拯救大兵瑞恩 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- 拯救大兵瑞恩 HDU - 4845(状压bfs || 分层最短路)
1.状压bfs 这个状压体现在key上 我i们用把key状压一下 就能记录到一个点时 已经拥有的key的种类 ban[x1][y1][x2][y1]记录两个点之间的状态 是门 还是墙 还是啥都没有 ...
- HDU 4012 Paint on a Wall(状压+bfs)
Paint on a Wall Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU Stealing Harry Potter's Precious(状压BFS)
状压BFS 注意在用二维字符数组时,要把空格.换行处理好. #include<stdio.h> #include<algorithm> #include<string.h ...
- POJ 1324 Holedox Moving (状压BFS)
POJ 1324 Holedox Moving (状压BFS) Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18091 Acc ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- P2622 关灯问题II(状压bfs)
P2622 关灯问题II 题目描述 现有n盏灯,以及m个按钮.每个按钮可以同时控制这n盏灯——按下了第i个按钮,对于所有的灯都有一个效果.按下i按钮对于第j盏灯,是下面3中效果之一:如果a[i][j] ...
- 状压BFS
题意:1个机器人找几个垃圾,求出最短路径. 状压BFS,这道题不能用普通BFS二维vis标记数组去标记走过的路径,因为这题是可以往回走的,而且你也不能只记录垃圾的数量就可以了,因为它有可能重复走同一 ...
- HDU 3001 状压DP
有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路 成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...
随机推荐
- ATM作业
关于ATM作业,最近做了很久,才明白,其实看了很久的作业视频讲解,到不如将作业的整个下载下来进行运行,去了解程序本身的结构和运行方式.首先说需求,就感觉是各种懵逼,这才学了函数,和模块之间的简单调用就 ...
- openssl_error_string()
其实已经成功了,openssl_error_string()一样会输出错误信息,忽略就好
- Python之路(第二十一篇) re模块
一.re模块 正则表达式本身是一种小型的.高度专业化的编程语言,正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re,正则表达式模式被编译成一系列的字节码,然 ...
- 使用hMailServer搭建邮件服务器
本文没有什么高深的技术内容,只是使用hMailServer,介绍搭建邮件服务器的全过程,供参考. 一.安装邮件服务器组件 打开软件,点下一步 选择存储数据的数据库,这里有两种选择, 一种是使用嵌入型数 ...
- anaconda的源配置的坑
anaconda是一个python的科学计算的包集合,它提供了一个非常好用的包管理器 conda,类似于pip. 为了速度(不仅为了速度,没有清华源你就被墙了,速度为0),我们使用清华源: 在类uni ...
- Java学习笔记:注解Annotation
annotation的概念 In the Java computer programming language, an annotation is a form of syntactic metada ...
- javascript对象的属性,方法,prototype作用范围分析.
用了javascript这么久由于没有系统学习过基础,总是拿来主义. 所以对一些基础知识还是搞不清楚很混乱. 今天自己做个小例子,希望彻底能搞清楚. 注释中对象只例子的对象本身,原型只原型继承对象的新 ...
- python下使用opencv拍照
首先在命令中安装opencv: pip install opencv-python 然后打开notebook: jupyter notebook 建立文件,写入如下代码: import cv2 cap ...
- *1LL在c++中的意义
LL其实代表long long,*1LL是为了在计算时,把int类型的变量转化为long long,然后再赋值给long long类型的变量 ANS=1LL*num*((1LL)*n*(n-1))/2 ...
- 正则表达式,re模块
一.正则表达式 正则表达式 : 匹配字符串,一般用于爬取数据. 正则表达式查询网址 : http://tool.chinaz.com/regex/?qq-pf-to=pcqq.group 1.元字符( ...