Subway POJ 2502
题目链接:
http://poj.org/problem?id=2502
题目大意:
你刚从一个安静的小镇搬到一个吵闹的大城市,所以你不能再骑自行车去上学了,只能乘坐地铁或者步行去上学。因为你不想迟到,所以你想知道自己多长时间能到达学校,你步行的速度是 10km/h,
地铁的速度是40km/h, 假如你是幸运的,你刚到地铁就有一辆地铁行驶过来, 你马上就可以乘坐, 任意的一个地铁你可以乘坐多次,若果你愿意你可以换乘不同的地铁,所有的地铁都是两个方向的。
输入:
输入首先包含两个坐标,表示你家的坐标和学校的坐标,随后有几个规格的地铁线路, 每个地铁线路包含几个坐标, 每个坐标表示地铁的站台,地铁到这个坐标时会停止, 你可以假设地铁站之间是直线。给个坐标都是整数,每个地铁线路至少有两站,最后两个 -1 代表地铁的站结束,最多有200站,
输出:
输出一个分钟数,表示家到学校的最短时间。结果四舍五入
题目分析:
这题目难点就是在处理数据问题上,其他的都简单,但是有点是要注意的就是 铁路线的每个站点 并不是直线, 有可能是曲线, 因此在算距离的时候地铁的两个点并不能全部以直线距离来算
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
#define INF 0xffffffff
#define maxn 520 struct Point
{
double x, y;
int k;
}P[maxn]; bool vis[maxn];
int n;
double G[maxn][maxn], dist[maxn];
double Len(Point A, Point B)
{
return sqrt( 1.0*(A.x - B.x)*(A.x - B.x) + 1.0*(A.y - B.y)*(A.y - B.y) );
}
void Init()
{
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++)
{
dist[i] = INF;
}
}
void Input()
{
int k = ;
n = ; scanf("%lf%lf%lf%lf",&P[].x,&P[].y,&P[].x,&P[].y);
P[].k = , P[].k = ; while(scanf("%lf%lf",&P[n].x, &P[n].y) != EOF )
{
n ++;
P[n-].k = k; if( P[n-].x == - && P[n-].y == -)
{
n --;
k ++;
}
} for(int i=; i<n; i++)
{
for(int j=; j<=i; j++)
{
double len = Len(P[i], P[j]), time; time = len / 10000.0 * ; if(P[i].k == P[j].k && i == j+ )
{
time = len / 40000.0 * ;
} G[i][j] = time;
G[j][i] = G[i][j];
}
}
}
double Spfa()
{
int e = ; queue<int> Q; dist[] = ;
Q.push(e); while( !Q.empty() )
{
e = Q.front();
Q.pop(); vis[e] = false; for(int i=; i<n; i++)
{
if(dist[i] > dist[e] + G[e][i])
{
dist[i] = dist[e] + G[e][i]; if(!vis[i])
{
vis[i] = true;
Q.push(i);
}
}
}
}
return dist[];
} int main()
{ Input(); Init(); double ans = Spfa(); printf("%0.lf\n",ans); return ;
}
Subway POJ 2502的更多相关文章
- L - Subway - POJ 2502
题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h.现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到 ...
- Subway POJ - 2502 最短路
题意:给出地铁线 起点和 终点 坐地铁速度为v2 走路为v1 求起点到终点的最短距离 (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可 然后跑个迪杰斯特拉 #inclu ...
- Subway POJ - 2502 spfa
#include<cstdio> #include<cmath> #include<cstring> #include<cstring> #includ ...
- POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离)
POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) Description You have just moved from a ...
- POJ 2502 - Subway Dijkstra堆优化试水
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 Descriptio ...
- POJ 2502 Subway (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- POJ 2502 Subway
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 1602 Descriptio ...
- POJ 2502 Subway (最短路)
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
随机推荐
- Android 网络框架Volley的使用
Volley简介 在平时的开发过程中,我们的应用几乎总是在和网络打交道, 在android下的网络编程一般都是基于Http协议的 ,常见的是HttpURLConnection和HttpClient 两 ...
- C#中的操作数据库的SQLHelper类
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- Java 8 Lambda表达式10个示例【存】
PS:不能完全参考文章的代码,请参考这个文件http://files.cnblogs.com/files/AIThink/Test01.zip 在Java 8之前,如果想将行为传入函数,仅有的选择就是 ...
- ASP.NET图片验证码学习!
1. 新建一个Validate.aspx,然后在Validate.aspx.cs编写代码: using System; using System.Collections; using System.C ...
- Alibaba FastJson
import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSONObject class Test { static main(arg ...
- 分页技术之GridView控件
GridView控件实现分页技术 第一步:设置GridView控件的属性,跟分页相关的属性设置如下: AllowPaging="true":允许分页, PageSize=" ...
- dotnet与各种数据库类型对应关系
Data Provider Parameter format sqlclient @parametername oledb ? mark odbc ? mark oracleclient : ...
- oracle批量转库工作,比较快捷的方式
select 'create table ' || t.TABLE_NAME || ' as select * from ODS_ZMGLXT.'|| t.TABLE_NAME ||'; ' fr ...
- oracle解析xml完成版第二次修改
其实XML字符串就好像是ORACLE中的外部表,因此Oracle对 解析XML字符串一些规则要求非常严格.XML字符串提供的数据就是一张表,所以Oracle必须提供跟 xml数据一致的列头 示例一 S ...
- C++拾遗(三)关于复合类型
数组相关 初始化只能在定义的时候使用,不能把数组赋给另一个数组. 初始化可以提供比元素数目少的初值,其它元素将被置为0. 字符char数组只有在以\0结尾时才是一个字符串.sizeof()返回数组的长 ...