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

题意:

有一个迷宫,在迷宫中有墙与门 有m道墙,每一道墙表示为(x,y,d,t)
x,y表示墙的起始坐标
d为0即向右t个单位,都是墙
d为1即向上t个单位,都是墙
有n道门,每一道门表示为(x,y,d)
x,y表示门的起始坐标
d为0即向右一个单位表示门
d为1即向上一个单位表示门
再给出你起点的位置(f1,f2),并保证这个点的位置不会再墙或者门中,为起点到(0,0)最少要穿过多少条门

代码是根据网上大神的稍微改了一下,就交了

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std; #define maxn 250
#define inf 99999999
struct node
{
int x;
int y;
int len;
bool operator <(const node &a)const//运算符重载,就是根据len从小到大排序
{
return len>a.len;
}
}; int n,m,sx,sy,xmax,ymax;
int dis[maxn][maxn],h[maxn][maxn],l[maxn][maxn]; priority_queue<node>q;
void bfs()
{
int x,y;
for(x=; x<=xmax; x++)
{
for(y=; y<=ymax; y++)
dis[x][y]=inf;
}
while(!q.empty())q.pop();
node pn;
pn.x=;
pn.y=;
pn.len=;
dis[][]=;
q.push(pn);
while(!q.empty())
{
pn=q.top();
q.pop();
x=pn.x;
y=pn.y;
if(x==sx&&y==sy)return ; //向上走
if(y+<=ymax&&dis[x][y+]>dis[x][y]+h[x][y+])
{
dis[x][y+]=dis[x][y]+h[x][y+];
pn.x=x;
pn.y=y+;
pn.len=dis[x][y+];
q.push(pn);
}
if(y->=&&dis[x][y-]>dis[x][y]+h[x][y])//向下走
{
dis[x][y-]=dis[x][y]+h[x][y];
pn.x=x;
pn.y=y-;
pn.len=dis[x][y-];
q.push(pn);
}
if(x->=&&dis[x-][y]>dis[x][y]+l[x][y])//向左走
{
dis[x-][y]=dis[x][y]+l[x][y];
pn.x=x-;
pn.y=y;
pn.len=dis[x-][y];
q.push(pn);
}
if(x+<=xmax&&dis[x+][y]>dis[x][y]+l[x+][y])//向右走
{
dis[x+][y]=dis[x][y]+l[x+][y];
pn.x=x+;
pn.y=y;
pn.len=dis[x+][y];
q.push(pn);
}
}
dis[sx][sy]=-;
} int main()
{
int i,j,x,y,d,t;
double tx,ty;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(m==-&&n==-)break;
xmax=ymax=-;
memset(h,,sizeof(h));
memset(l,,sizeof(l));
for(i=; i<n; i++)
{
scanf("%d%d%d%d",&x,&y,&d,&t);
if(d==)
{
for(j=; j<t; j++)
{
h[x+j][y]=inf;
}
xmax=max(xmax,x+t);
ymax=max(ymax,y);
}
else
{
for(j=; j<t; j++)
{
l[x][y+j]=inf;
}
xmax=max(xmax,x);
ymax=max(ymax,y+t);
}
}
for(i=; i<m; i++)
{
scanf("%d%d%d",&x,&y,&d);
if(d==)
{
h[x][y]=;
}
else l[x][y]=;
}
scanf("%lf%lf",&tx,&ty);
if(tx>xmax||ty>ymax)
{
printf("0\n");
}
else
{
sx=(int)tx;
sy=(int)ty;
bfs();
printf("%d\n",dis[sx][sy]);
}
}
}

poj 2049 Finding Nemo(优先队列+bfs)的更多相关文章

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

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

  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. Finding Nemo(bfs)

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

  5. poj 2312 Battle City(优先队列+bfs)

    题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...

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

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

  7. POJ 2449 - Remmarguts' Date - [第k短路模板题][优先队列BFS]

    题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good m ...

  8. hdu 1026 Ignatius and the Princess I【优先队列+BFS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

随机推荐

  1. wamp Server2.5 配置 自定义目录

    煎熬了两天终于找到了方法!!! 前提先改成中文 右键"W"图表-> Language -> chinese; 成功改为中文. 自定义目录步骤: 一.添加一个Alias ...

  2. jQueryr .on方法解析

    .On() 其实.bind(), .live(), .delegate()都是通过.on()来实现的,.unbind(), .die(), .undelegate(),也是一样的都是通过.off()来 ...

  3. linux下rm误删除数据库文件的恢复方法

    在linux redhat 5.4版本,rm误删除数据库文件的恢复过程分享.测试没有问题,可用. 1.首先测试rm 误删除数据库文件 [oracle@primary dbwdn]$ ll total ...

  4. IP HELPER GetAdaptersAddresses 函数

    自己做的一些笔记,XP以及以后的系统使用: MSDN 函数:http://msdn.microsoft.com/en-US/library/windows/desktop/aa365915(v=vs. ...

  5. xml学习总结(一)

    xml DTD 定义元素<!ELEMENT 元素名 元素类型描述 > (1)元素类型描述:任意类型,字符串型,空元素,包含子元素,混合类型 任意类型: <?xml version=& ...

  6. (转)Qt Model/View 学习笔记 (二)——Qt Model/View模式举例

    Qt Model/View模式举例 Qt提供了两个标准的models:QStandardItemModel和QDirModel.QStandardItemModel是一个多用途的model,可用于表示 ...

  7. sharepoint One-Time Passwords (windows basic authentication)

    //设计中,未完成 references: http://www.asp.net/web-api/overview/security/basic-authentication http://techn ...

  8. shell 后台执行命令

    shell 后台执行命令方法: 1. nohup cmd &          后台会生成 nohup.out 文件 2.cmd >/路径/xx.log &   后台生成 xx. ...

  9. python学习笔记3(字符串)

    Python字符串: 在Python中的字符串被确定为一组连续的字符在引号之间, Python允许在任何对单引号或双引号. 串的子集,可以使用切片操作符可采用([]和[:]),索引从0开始的字符串的开 ...

  10. SwfUpload vs里运行可以上传文件,放到iis上上传就报404错误。

    网上的答案都是说swfupload 的upload_url 路径要设置成绝对路径,但是我也设置了,但是还是不行,然后又找了方法,终于找到了,点击这里查看 解决办法: <system.webSer ...