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: 然后这个人想去旅行.有个超人开始可以把他扔到 ...
随机推荐
- C++中的fstream,ifstream,oftream
https://blog.csdn.net/kingstar158/article/details/6859379 先mark一个大佬的随笔,有时间再回头看 总结: 使用ifstream和ofstre ...
- (轉)JSON.stringify 语法实例讲解
作用:这个函数的作用主要是为了系列化对象的. 可能有些人对系列化这个词过敏,我的理解很简单.就是说把原来是对象的类型转换成字符串类型(或者更确切的说是json类型的).就这么简单.打个比方说,你有一个 ...
- Executors提供的四种线程池
Java 5+中的Executor接口定义一个执行线程的工具.它的子类型即线程池接口是ExecutorService.要配置一个线程池是比较复杂的,尤其是对于线程池的原理不是很清楚的情况下,因此在工具 ...
- 大神你好,可以帮我P张图吗?
韩国版的求大神帮我P张图,看得有点下巴脱臼啊!哈哈哈哈哈哈哈~ 感觉照片拍得很尴尬,请大神P得更有动感 拍了跳跃照片,但内衣露出来一点,能帮忙去掉吗 不喜欢没穿制服的样子,请帮忙加上制服 希望背景 ...
- sqli-labs:23/25-28,绕waf
sqli23: and|or型报错 ' or extractvalue(1,concat(0x7e,database())) or '1'='1 union型嵌套select ' union sele ...
- Git简单操作命令
Git 1.创建远程分支(git项目已在) git checkout -b cgy git add . git commit -m “add new branch” git push origin c ...
- QueryRunner类的八种结果处理集
package cn.jy.demo; import java.sql.Connection; import java.sql.SQLException; import java.util.List; ...
- TCP与UDP传输协议
目录结构: contents structure [-] 1 TCP协议和UDP协议的比较 1.1 TCP协议 TCP的全称是Transmission Control Protocol (传输控制协议 ...
- springMVC学习 六 跳转方式
SpringMVC的controller中的方法执行完之后,默认的跳转方式是请求转发 如果想要修改跳转方式,可以设置返回值字符串内容(1) 添加 redirect:资源路径 重定向 "red ...
- CSS-弹性布局-伪类选择器-复杂选择器
1.定位 1.堆叠顺序 一旦将元素变为已定位元素的话,元素们则有可能出现堆叠的效果. 如何改变堆叠顺序? 属性:z-index 取值:无单位的数字,数字越大越靠上. 注意: 1.父子元素间,z-ind ...