HDU_5094_dfs
http://acm.hdu.edu.cn/showproblem.php?pid=5094
bfs,vis[x][y][z],z表示钥匙的状态,用二进制来表示,key[x][y]储存当前位置钥匙的二进制表示。
注意起始点有钥匙的情况。
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std; struct point
{
int x,y,counts,mykey;
}start; int n,m,p,k,s,flag,door[][][][],key[][],vis[][][],dir[][] = {-,,,-,,,,}; int main()
{
while(~scanf("%d%d%d",&n,&m,&p))
{
memset(door,-,sizeof(door));
memset(key,,sizeof(key));
memset(vis,,sizeof(vis));
scanf("%d",&k);
int x1,y1,x2,y2,type;
while(k--)
{
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&type);
door[x1][y1][x2][y2] = type;
door[x2][y2][x1][y1] = type;
}
scanf("%d",&s);
int x,y,keytype;
while(s--)
{
scanf("%d%d%d",&x,&y,&keytype);
key[x][y] |= <<(keytype-);
}
queue<point> q;
start.x = ;
start.y = ;
start.counts = ;
start.mykey = key[][];
vis[][][start.mykey] = ;
q.push(start);
flag = ;
while(!q.empty())
{ point now = q.front();
q.pop();
if(now.x == n && now.y == m)
{
flag = ;
printf("%d\n",now.counts);
break;
}
for(int i = ;i < ;i++)
{
point temp;
temp.x = now.x+dir[i][];
temp.y = now.y+dir[i][];
if(temp.x < || temp.x > n || temp.y < || temp.y > m) continue;
if(door[now.x][now.y][temp.x][temp.y] != - &&(now.mykey & <<(door[now.x][now.y][temp.x][temp.y]-)) == ) continue;
temp.counts = now.counts+;
temp.mykey = now.mykey | key[temp.x][temp.y];
if(vis[temp.x][temp.y][temp.mykey]) continue;
vis[temp.x][temp.y][temp.mykey] = ;
q.push(temp);
}
}
if(flag) printf("-1\n");
}
}
HDU_5094_dfs的更多相关文章
随机推荐
- Mac重装操作系统系统
恢复出厂设置 第一种 1.开机 2.commond + R,进入recover模式. 3.选择磁盘工具 4.显示所有设备 5.抹掉硬盘.格式选择 (1):Mac OS 扩展(日志式). (2): Ma ...
- 解决Maven项目中的无故报错的方法
解决Eclipse+maven中的无故报错 错误: One or more constraints have not been satisfied. Deployment Assembly跟java版 ...
- esri mdb 数据库导入 到postgreSQL
需求: 项目升级,需要将esri的个人数据库(mdb格式)导入到开源数据库postgreSQL中. 思路: 使用fwtools工具导出到数据库中. 环境: windows+fwtools+postgr ...
- cannot mount volume over existing file, file exists /var/lib/docker/overlay2/.../merged/usr/share/zoneinfo/UTC 解决
问题产生原因: linux系统docker-compose.yml文件 放到 mac本启动发现启动报错 cannot mount volume over existing file, file exi ...
- 速石科技携HPC混合云平台亮相AWS技术峰会2019上海站
2019年6月20日,全球云技术盛会——AWS技术峰会2019(上海站)在上海世博中心举行.作为AWS的技术合作伙伴,速石科技携旗下基于混合云的一站式高性能计算(HPC)平台首次公开亮相. 速石科技向 ...
- Rust入坑指南:海纳百川
今天来聊Rust中两个重要的概念:泛型和trait.很多编程语言都支持泛型,Rust也不例外,相信大家对泛型也都比较熟悉,它可以表示任意一种数据类型.trait同样不是Rust所特有的特性,它借鉴于H ...
- 一步一步教你PowerBI利用爬虫获取天气数据分析
对于爬虫大家应该不会陌生,我们首先来看一下爬虫的定义:网络爬虫是一种自动获取网页内容的程序,是搜索引擎的重要组成部分.网络爬虫为搜索引擎从万维网下载网页,自动获取网页内容的应用程序.看到定义我们应该已 ...
- sender e
sender 产生事件的对象e 事件的参数
- 替代not in 和 in 的办法
在程序中,我们经常会习惯性的使用in和not in,在访问量比较小的时候是可以的,但是一旦数据量大了,我们就推荐使用not exists或者外连接来代替了.如果要实现一张表有而另外一张表没有的数据时, ...
- 基于iTextSharp的PDF操作(PDF打印,PDF下载)
基于iTextSharp的PDF操作(PDF打印,PDF下载) 准备 1. iTextSharp的简介 iTextSharp是一个移植于java平台的iText项目,被封装成c#的组件来用于C#生成P ...