poj 2049 Finding Nemo(优先队列+bfs)
题目: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)的更多相关文章
- POJ 2049— Finding Nemo(三维BFS)10/200
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...
- POJ 2049 Finding Nemo bfs 建图很难。。
Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 6952 Accepted: 1584 Desc ...
- POJ 2049 Finding Nemo
Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 8631 Accepted: 2019 Desc ...
- Finding Nemo(bfs)
Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 6988 Accepted: 1600 Description Nemo ...
- poj 2312 Battle City(优先队列+bfs)
题目链接:http://poj.org/problem?id=2312 题目大意:给出一个n*m的矩阵,其中Y是起点,T是终点,B和E可以走,S和R不可以走,要注意的是走B需要2分钟,走E需要一分钟. ...
- Finding Nemo 分类: POJ 2015-07-11 10:11 10人阅读 评论(0) 收藏
Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 8117 Accepted: 1883 Desc ...
- POJ 2449 - Remmarguts' Date - [第k短路模板题][优先队列BFS]
题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good m ...
- 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 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
随机推荐
- H5全景视频VR视频
公司的有个专题页面涉及到全景视频展示这个技术点,找到一个相关的库. http://www.utovr.com/sdk/download 这里有个免费的SDK可以下载. 里面也有案例可以看,代码就照着 ...
- Review PHP设计模式之——单例模式
单例模式: class Single { private static $_instance; private function __construct(){ //define method as p ...
- UTF8后MD5
function ToUTF8Encode(str: string): string; //将字符串转UTF8编码 var b: Byte; begin for b in BytesOf(UTF8En ...
- Demo学习: ClientEvents
ClientEvents 在控件的ClientEvents属性里嵌入JS代码,增加了开发的灵活性. 分别在TUniPanel和TUniTimer的 ClientEvents事件里添加了JS代码: 1. ...
- 1079. Total Sales of Supply Chain (25)
时间限制 250 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A supply chain is a network of r ...
- fedora安装postgresql
1. 安装:postgresql-server pgadmin程序 sudo yum install postgresql-server.x86_64 sudo yum install pgadmin ...
- 2016 系统设计第一期 (档案一)MVC 和 Bootstrap 表单转换
bootstrap <form role="form"> <div class="form-group"> <label for= ...
- c# 赋值后最后一项数据部分丢失
赋值,赋值后 原因,在添加后立即调用clear()清除数据....
- kill 进程卡住,超时kill方法
还是有漏洞 ,万一 working.py未超时, kill_job.sh 会不会杀死别人的进程啊start.sh#!/bin/bash python working.py &python wo ...
- SQL的表连接
每天给自己扫盲,让自己变得越博学. 继续学习<程序员的SQL金典>,这回我们来看看表连接相关的内容.表连接的相关知识在实际的项目开发当中,使用非常广. 所谓表连接,就是通过关联多张表,从而 ...