题目: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. js自运行函数

    学习闭包的基础知识: 函数声明 function fn(){ //这里是代码 }; fn(); //运行fn函数 与上面等价 var fn = function(){ //这里是代码 } fn(); ...

  2. 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.

    一:使用jsonp格式, 如jquery中ajax请求参数   dataType:'JSONP'. <html> <head> <title>title</t ...

  3. uniquery 在win2008 下hold的问题。

    TmpQry.ReadOnly := True; 加上这句解决,原因未知!

  4. 《WPF程序设计指南》读书笔记——第5章 Stack与Wrap

    1.StackPanel面板 using System; using System.Windows; using System.Windows.Input; using System.Windows. ...

  5. The Black Hole of Numbers (strtoint+inttostr+sort)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  6. 奖学金评分系统(系统分析与设计版与Delphi实现代码)

    一.系统规划 1.1 项目背景介绍 在奖学金评比过程中,学生综合测评是学校普遍采用的评比手段.对学生实施综合素质测评的目的在于正确评价学生的综合素质,为评奖学金提供依据,实现学生教育管理工作的标准化. ...

  7. http中的KeepAlive

    为什么要使用KeepAlive? 终极的原因就是需要加快客户端和服务端的访问请求速度.KeepAlive就是浏览器和服务端之间保持长连接,这个连接是可以复用的.当客户端发送一次请求,收到相应以后,第二 ...

  8. 我的PHP之旅--XML初步

    什么是XML? XML是可拓展标记语言,它和XHTML很像.但它和XHTML的目的性不一样,XHTML负责展示数据,而XML负责保存或交换传输数据. 而且XML可拓展,它没有固定的标签.它的标签可以自 ...

  9. Mybatis+SpringMVC的项目环境搭建

    一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  10. mysql可以运行在不同sql mode模式下面,sql mode模式定义了mysql应该支持的sql语法,数据校验等

    查看默认的sql mode模式:select @@sql_mode;我的数据库是:STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUT ...