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. 题解 洛谷P3203/BZOJ2002【[HNOI2010]弹飞绵羊】

    裸的LCT,关键是要怎么连边,怎么将这种弹飞关系转化成连边就行了. 那么我们可以这样连边: 一个节点i的爸爸就是i+ki. 没有i+ki那么就被弹飞了,即\(i\)的爸爸是虚拟节点n+1. 那么怎么求 ...

  2. Flask项目中整合各组件

    一.介绍 主要介绍flask_sqlalchemy.flask_script.flask_migrate这三个组件该如何整合到flask项目中,以及如何使用. # 安装组件 pip3 install ...

  3. 创建sum求多元素的和

    a = [1, 2, 3] b = [4, 5, 6] def sum_super(* args): s = 0 for i in args: s += sum(i) return s # print ...

  4. PyCharm开发GUI之PyQt安装

    开发环境 PyCharm 2018.3.3python3.7 1 安装pyqt5 pip install PyQt5-tools 2 配置PyCharm 2.1 配置设计器 其中,program为C: ...

  5. Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了

    insertSelective---Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了 https://www.cnblogs.com/xi ...

  6. HDU 4902 (牛叉的线段树)

    Nice boat Problem Description There is an old country and the king fell in love with a devil. The de ...

  7. (13)Corner Detection角点检测

    import cv2 import numpy as np img=cv2.imread('opencv-corner-detection-sample.jpg') gray = cv2.cvtCol ...

  8. php处理管道文件流

    <?php #!/usr/local/bin/php -q function read(){ $fp = fopen("php://stdin", "r" ...

  9. 如何取消codeblocks对msvcr100.dll的依赖?

    用VS2010或是codeblocks开发的程序,在开发之外的机器上,可能会提前缺少msvcr100.dll之类的文件. 可以用如何设置,取消其对库文件的依赖. 当然,还要注意创建程序的类型.(补) ...

  10. [bzoj3668][Noi2014]起床困难综合症_暴力

    起床困难综合征 bzoj-3668 Noi-2014 题目大意:题目链接. 注释:略. 想法:Noi考这题...联赛T1难度.... 我们将每个门上的数二进制拆分. 发现:当前位的操作可能直接确定了当 ...