POJ 2502 Subway(迪杰斯特拉)

OpenClaw插件配置错误修复完全指南 插件文件名是插件目录结构正确package.json配置正确OpenClaw的插件系统还在快速迭代,偶尔会遇到这种配置问题。看错误信息检查配置文件检查实际文件对比差异修复问题大部分问题都能解决。查看官方文档:https://openclaw.ai/docs提Issue:https://github.com/openclaw/openclaw/issues加入Discord社区求助快速修复命令汇总。 阅读详情

Subway
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6692 Accepted: 2177

Description

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want to know how long it will take you to get to school. 
You walk at a speed of 10 km/h. The subway travels at 40 km/h. Assume that you are lucky, and whenever you arrive at a subway station, a train is there that you can board immediately. You may get on and off the subway any number of times, and you may switch between different subway lines if you wish. All subway lines go in both directions.

Input

Input consists of the x,y coordinates of your home and your school, followed by specifications of several subway lines. Each subway line consists of the non-negative integer x,y coordinates of each stop on the line, in order. You may assume the subway runs in a straight line between adjacent stops, and the coordinates represent an integral number of metres. Each line has at least two stops. The end of each subway line is followed by the dummy coordinate pair -1,-1. In total there are at most 200 subway stops in the city.

Output

Output is the number of minutes it will take you to get to school, rounded to the nearest minute, taking the fastest route.

Sample Input

0 0 10000 1000
0 200 5000 200 7000 200 -1 -1 
2000 600 5000 600 10000 600 -1 -1

Sample Output

21

题目链接:http://poj.org/problem?id=2502


题目大意:给出家和学校坐标表示固定的起点和终点,接下来每一行代表一条地铁线,输入该条地铁线的每个站点的坐标,以-1,-1(不是坐标)结束一行,保证地铁线沿直线,且至少有两站。给出乘地铁和步行的不同速度,求一个人从家到学校用到的最小时间。


解题思路:构建无向图,时间为权值,用迪杰斯特拉算法,求家到学校两个结点最短路径问题。同一条地铁线上两站间的时间先计算出来,输入结束,没有权值任意两以步行的速度计算时间。注意输入格式,以EOF结束。

补充:Dijkstra算法适用于权值都为正的图结构,dist[ i ]数组存储 i 到起点v0 的最短路长度,初始为邻接矩阵eg[v0][i]值无穷大.遍历n-1次找出n-1条最短路。s[i ]数组记录结点是否已确定最小dist[ i ],初始为0,确定后为1,找到的i值赋为u,以u为起点找下一个距离u最近的节点j,更新条件:dist [ j ] = min(dist [ u ]+eg [ v0 ] [ u ],dist [ j ]),保证每个点距离起点的距离最短。如果要记录路径,要用到path数组,如果通过u找到了j,path [ j ]=u记录即可。


代码如下:

#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 100000000.0;
int const maxn=400;
int s[maxn];
double dist[maxn];
double eg[maxn][maxn];
int num;

struct  A
{
    double x,y;
}stop[maxn];
double lenth(double x1,double y1,double x2,double y2)
{
    double a=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    return sqrt(a);
}

void Dijkstra(int v0)
{
    int i,j;
    for(i=0;i<num;i++)
    {
        s[i]=0;
        dist[i]=eg[v0][i];
    }
    s[v0]=1;
    for(i=0;i<num-1;i++)
    {
        double min=INF;
        int u;
        for(j=0;j<num;j++)
        {
            if(!s[j] && dist[j]<min)
            {
                u=j;
                min=dist[j];
            }
        }
        s[u]=1;
        for(j=0;j<num;j++)
        {
            if(!s[j] && dist[u]+eg[u][j]<dist[j])
                dist[j]=dist[u]+eg[u][j];
        }
    }
}

int main()
{
    int i,j;
    double x1,x2,y1,y2;
    memset(eg,0,sizeof(eg));
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	stop[0].x=x1;
	stop[0].y=y1;
	stop[1].x=x2;
	stop[1].y=y2;
    num=2;
    int p=0;
    while(scanf("%lf%lf",&stop[num].x,&stop[num].y)!=EOF)
    {
        if(stop[num].x==-1 && stop[num].y==-1)
        {
            p=0;
            continue;
        }
        if(!p)
        {
            p=1;
            num++;
            continue;
        }
        eg[num-1][num]=eg[num][num-1]=lenth(stop[num-1].x,stop[num-1].y,stop[num].x,stop[num].y)/4000.0;
        num++;
    }  
	for(i=0;i<num;i++)
    {
        for(j=i+1;j<num;j++)
            if(eg[i][j]==0 )
                eg[i][j]=eg[j][i]=lenth(stop[i].x,stop[i].y,stop[j].x,stop[j].y)/1000.0;
    }
	Dijkstra(0);
	printf("%d\n",int(0.5+6.0*dist[1]) );
	return 0;
}


高云FPGA系列教程(7):ARM GPIO外部中断 高云GN1NSR-4C共有16个GPIO,每个GPIO可配置成输入或输出模式,支持中断输入,触发方式可选择:上升沿、下降沿、高电平、低电平触发。中断优先级可通过NVIC进行设置,支持 0-7 级可编程中断优先级。 阅读详情

相关推荐

【FDTD运行引擎错误解决方法】

我用的是2024R1版的FDTD,第一次安装好的时候点“RUN”可以正常运行,后来不知道什么问题就无法运行了。我从网上找相关的解决办法,并未找到,将软件卸载重装,重启等方法都没有解决,后来在官网按照提示解决了,我把官网提供的方式和我的情况相结合,提供一个解决方式。提示:以下是本篇文章正文内容,下面案例可供参考最后说一下两个MPI和Local computer(不使用MPI)的区别使用MPI进行仿真可以显著提高计算速度和效率,特别是对于大规模和复杂的仿真任务,但需要额外的设置和配置。(多线程并行计算)

m0_57410975的博客 8201

POJ2502 subway

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want

LSC_333的博客 336

深入解析ffmpeg编码错误:avcodec_send_frame()返回-22的排查与修复

本文深入解析FFmpeg编码中avcodec_send_frame()返回-22(AVERROR(EINVAL))错误的根本原因与系统排查方法。核心问题通常在于编码器未正确打开或上下文传递错误。文章提供了从检查编码器查找、确认avcodec_open2()调用,到验证上下文传递的完整修复指南,并附有可运行的代码示例,帮助开发者快速定位并解决这一常见编码障碍。

weixin_28049429的博客 399

POJ - 2502Subway

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don’t want t

dreambyday 364

Latex里面关于作者名字显示有灰色; 二级+三级标题斜体;

Latex里面关于 作者名字显示有灰色; 二级+三级标题斜体,与正文的距离; 邮箱字体;ORCID字体设置(整理不易,请先关注,Thanks)

m0_61015717的博客 751

【树莓派4B】八、树莓派软路由,Ubuntu18.04配置路由转发

我的目的是通过把树莓派做成一个软路由,相当于一个智能路由器。 材料 树莓派4B,操作系统其实可以是其他的Linux版本。以为4B自带无线网卡,就用自带无线网卡作为路由出口。 大概思路 具体步骤 配置两个网卡的IP sudo vim /etc/network/interface 这里设置静态IP,也可以动态获取。 #Local loopback auto lo iface lo inet loopback #Ethernet0 auto eth0 iface eth0 inet static addr

林愿留的博客 10万+

POJ 2502-Subway(最短路水题)

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want ...

PleasantlY1的博客 578

利用GBD数据库做未来疾病负担预测

最近看到一篇文献,利用GBD数据库中的数据对疾病负担的发展趋势进行预测。觉得很有趣,就抽空用R语言复盘了一下里面关键的方法。 参考文献: Changing trends in the disease burden of esophageal cancer in China from 1990 to 2017 and its predicted level in 25 years DOI: 10.1002/cam4.3775 1. 相关R包的安装 主要用到的R包有3个,一个一个讲: 1.1 Nordpred

NickyCat的博客 5万+

POJ - 2502

Subway Time Limit:1000MS Memory Limit:65536K Total Submissions:10501 Accepted:3429 Description You have just moved from a quiet Waterloo neighbourhood to a big, n

林思少的博客 449

DAC8568实战指南:如何用STM32实现8通道DAC精准控制(附代码)

本文提供DAC8568与STM32结合的实战指南,详细解析8通道16位DAC的精准控制方法。内容涵盖硬件连接、SPI配置、驱动层构建、时序调试及多通道同步输出等关键步骤,并附有经过验证的HAL库驱动代码,帮助工程师快速解决实际项目中的通信与输出稳定性问题。

weixin_29175469的博客 760

【100%通过率】华为OD机试真题 JS 实现【水库蓄水问题】【2023 Q1 | 100分】

给定一个长度为 n 的整数数组height。数组的元素表示山的高度,选择两个元素作为水库的边界,求蓄水量的最大值并输出蓄水量最大时的边界下标(蓄水量相同时输出下标较近的)。

MISAYAONE的博客 8179

(简单) POJ 2502 Subway,Dijkstra。

  Description   You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. B...

weixin_30739595的博客 128

【TC3xx芯片】TC3xx芯片PFlash的ECC校验问题补充

TC3xx芯片PFlash的ECC校验问题补充

qq_36056498的博客 1164

POJ 2502 Subway(将各种数据转化成图+最短路+迪杰斯特拉算法)

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want to know how long it will

HJY 637

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj——2502——Subway

Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because

清溪浅水 627

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

poj 2502 Subway

http://poj.org/problem?id=2502 Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7886   Accepted: 2545 Description You have just moved from a qui

大太阳 578

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Subway POJ - 2502 最短路

题意:给出地铁线 起点和 终点 坐地铁速度为v2 走路为v1 求起点到终点的最短距离 (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可 然后跑个迪杰斯特拉 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include...

azmkinbug41973327的博客 162

POJ 2502 Subway (最短路)

Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bik...

dituonian8372的博客 161

POJ-2502 Subway

http://poj.org/problem?id=2502 这题本来应该用迪杰斯特拉做的 ,因为想试试弗洛伊德所以就试试 谁知道代码一一直wrong ,路过的麻烦指点一下 代码一: #include&lt;stdio.h&gt; #include&lt;math.h&gt; struct node { double x; double y; }node[205]; ...

weixin_34007906的博客 103

POJ 2502 Subway

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want

CS33sun的博客 397

POJ 2502 Subway

题目大意:首先给你两个坐标,一个是你家里的坐标,一个是你学校的坐标,然后接下来有若干条地铁线,每条地铁线上有若干个站点,给出每个站点的坐标,有这些点,这些点当中有距离,这个距离的单位是米,现在告诉你走路是10km/h,做地铁的话是40km/h,问你从家里到学校所花费的最短时间(分钟) 解题思路:这个主要是卡的输入,只要将输入弄好了,构成一张图就好做了,然后需要注意的是,对于地铁线,你从1站到

小马的博客 359

Subway POJ - 2502

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want

一念风华的博客 419

poj 2502 Subway (最短路 Dijksta)

Subway (最短路 ) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8323   Accepted: 2690 Description You have just moved from a quiet Waterloo neighbourhood to a big, no

Kunaly 660

POJ - 2502 J - Subway

You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want...

Vace___yun的博客 198
上一篇: POJ 1751 Highways
下一篇: noj 2030 收购计划
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址