http://poj.org/problem?id=2049

题意:有一个迷宫,迷宫中有墙、门和空地。有M道墙,每一道墙用(x,y,d,t)表示,(x,y)表示墙的起始坐标,(d=1,t)表示向上t个单位都是墙;(d=0,t)表示向右t个单位都是墙。

有N扇门,用(x,y,d)表示,(x,y)表示门的起始坐标,d=1,表示向上一个单位都是门;d=0,表示向右一个单位都是门。 给出Nemo的起始位置(f1,f2),问起点到(0,0)的最少要穿过的门。

表示对搜索的题很晕。。看到题不知道该怎么存,看了别人的题解才懂点。。

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
using namespace std;
const int INF=<<;
const int N=;
int dir[][]= {{-,},{,},{,-},{,}};
int xx[N][N],yy[N][N];
int dis[N][N];
int max_x,max_y;
int boundary(int x,int y)//边界判断
{
if(x> && x<=max_x && y<=max_y && y>)
return ;
return ;
}
int change(int x,int y,int d)//方向转换
{
if(d==) return yy[x-][y];
if(d==) return yy[x][y];
if(d==) return xx[x][y-];
return xx[x][y];
}
int bfs(int x,int y)
{
queue<int>q;
while(!q.empty()) q.pop();
for (int i = ; i <= max_y; i++)
{
for (int j = ; j <= max_x; j++)
dis[i][j] = INF;
}
dis[][]=;
q.push();
q.push();
while(!q.empty())
{
int x1=q.front();
q.pop();
int y1=q.front();
q.pop();
for (int i = ; i < ; i++)
{
int dx = x1+dir[i][];
int dy = y1+dir[i][];
int turn = change(x1,y1,i);
if(boundary(dx,dy) && dis[dx][dy]>dis[x1][y1]+turn)
{
dis[dx][dy]=dis[x1][y1]+turn;//更新最小步数
q.push(dx);
q.push(dy);
}
}
}
int ans = dis[x][y]==INF?-:dis[x][y];
return ans;
}
int main()
{
int n,m;
int x,y,d,l;
while(~scanf("%d%d",&n,&m))
{
if(n==-&&m==-) break;
max_x = max_y = -;
memset(xx,,sizeof(xx));
memset(yy,,sizeof(yy));
for (int i = ; i < n; i++)
{
scanf("%d%d%d%d",&x,&y,&d,&l);
if(d)
{
for (int j = ; j < l; j++)
yy[x][y+j+]=INF;
max_y=max(y+l+,max_y);
max_x=max(x+,max_x);
}
else
{
for (int j = ; j < l; j++)
{
xx[x+j+][y]=INF;
max_y=max(y+,max_y);
max_x=max(x+l+,max_x);
}
}
}
for (int i = ; i < m; i++)
{
scanf("%d%d%d",&x,&y,&d);
if(d) yy[x][y+]=;
else xx[x+][y]=;
}
double sx,sy;
int sx1,sy1;
scanf("%lf%lf",&sx,&sy);
sx1 = (int)sx+;
sy1 = (int)sy+;
if(!(sx>= && sx<= && sy>= && sy<=))//Nemo可能在迷宫外
printf("0\n");
else
printf("%d\n",bfs(sx1,sy1));
}
return ;
}

Finding Nemo(搜索)的更多相关文章

  1. Finding Nemo 分类: POJ 2015-07-11 10:11 10人阅读 评论(0) 收藏

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 8117   Accepted: 1883 Desc ...

  2. POJ 2049 Finding Nemo bfs 建图很难。。

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 6952   Accepted: 1584 Desc ...

  3. POJ 2049 Finding Nemo

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 8631   Accepted: 2019 Desc ...

  4. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

  5. Finding Nemo(bfs)

    Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 6988   Accepted: 1600 Description Nemo ...

  6. poj 2049 Finding Nemo(优先队列+bfs)

    题目:http://poj.org/problem?id=2049 题意: 有一个迷宫,在迷宫中有墙与门 有m道墙,每一道墙表示为(x,y,d,t)x,y表示墙的起始坐标d为0即向右t个单位,都是墙d ...

  7. POJ2049Finding Nemo(bfs + 构图)

    Finding Nemo Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 8456   Accepted: 1975 Desc ...

  8. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. [zz]Lessons from Pixar: Why Software Developers Should Be Storytellers

    http://firstround.com/article/lessons-from-pixar-why-software-developers-should-be-story-tellers Whe ...

随机推荐

  1. 什么是 C 和 C ++ 标准库?

    简要介绍编写C/C ++应用程序的领域,标准库的作用以及它是如何在各种操作系统中实现的. 我已经接触C++一段时间了,一开始就让我感到疑惑的是其内部结构:我所使用的内核函数和类从何而来? 谁发明了它们 ...

  2. 洛谷——P1549 棋盘问题(2)

    P1549 棋盘问题(2) 搜索||打表 #include<cstdio> #include<cstring> #include<iostream> #includ ...

  3. [LNOI2014]LCA(树链剖分)

    BZOJ传送门 Luogu传送门 题目:给你一棵树,给你n个询问,每个询问要求输出$\sum_{i=l}^{r}depth(LCA(i,z))$ 细看看其实没有想象的那么难 大体思路: 1.对于每个询 ...

  4. [luogu4127 AHOI2009] 同类分布 (数位dp)

    传送门 Solution 裸数位dp,空间存不下只能枚举数字具体是什么 注意memset最好为-1,不要是0,有很多状态答案为0 Code //By Menteur_Hxy #include < ...

  5. 服务器做ssh免秘钥登陆

    集群内服务器做非root用户免秘钥登陆:1.node1新建用户abc1,制作公钥.私钥(一路回车键即可)ssh-keygen –t rsa将自动在/home/abc1/.ssh/目录下创建公私钥文件如 ...

  6. linux ifstat-统计网络接口流量状态

    推荐:更多linux 性能监测与优化 关注:linux命令大全 ifstat命令就像iostat/vmstat描述其它的系统状况一样,是一个统计网络接口活动状态的工具.ifstat工具系统中并不默认安 ...

  7. 第九节:web爬虫之urllib(五)

    第四个模块 robotparser: 主要是用来识别网站的 robots.txt 文件,然后判断哪些网站可以爬,哪些网站不可以爬的,其实用的比较少.

  8. Prüfer序列和cayley定理

    参考资料: 1.matrix67 <经典证明:Prüfer编码与Cayley公式> 2.百度百科 3.Forget_forever prufer序列总结 4.维基百科 5.dirge的学习 ...

  9. idea 背景颜色设置

    1. 设置当前鼠标所在行颜色 2. 设置编辑区颜色

  10. [K/3Cloud]关于K/3 Cloud v2.0升级补丁的疑问

    现在除了K/3 Cloud v2.0的正式版之外,后续又发布了SP1和SP2补丁包.改善了一些问题和BUG,有些人之前可能之前装了SP1,有的可能没装过.在这里我说明一下: 不管装没装过补丁直接打SP ...