Dijkstra+计算几何 POJ 2502 Subway
题意:列车上行驶40, 其余走路速度10.问从家到学校的最短时间
分析:关键是建图:相邻站点的速度是40,否则都可以走路10的速度.读入数据也很变态.
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std; const int N = 2e2 + 5;
const int E = N * N;
const double INF = 1e30;
struct Point {
double x, y;
}p[N];
bool vis[N];
double d[N];
double w[N][N];
double sx, sy, ex, ey;
int tot; void Dijkstra(int s) {
memset (vis, false, sizeof (vis));
for (int i=1; i<=tot; ++i) {
d[i] = INF;
}
d[s] = 0;
for (int i=1; i<=tot; ++i) {
double mn = INF; int x = -1;
for (int j=1; j<=tot; ++j) {
if (!vis[j] && mn > d[j]) mn = d[x=j];
}
if (x == -1) break;
vis[x] = true;
for (int j=1; j<=tot; ++j) {
if (!vis[j] && d[j] > d[x] + w[x][j]) {
d[j] = d[x] + w[x][j];
}
}
}
} double squ(double x) {
return x * x;
} double get_cost(Point p1, Point p2, int v) {
double dis = sqrt (squ (p1.x - p2.x) + squ (p1.y - p2.y)) / 1000;
return dis / v;
} int main(void) {
while (scanf ("%lf%lf%lf%lf", &sx, &sy, &ex, &ey) == 4) {
for (int i=1; i<N; ++i) {
for (int j=1; j<N; ++j) {
w[i][j] = INF;
}
}
tot = 1;
double x, y, l = tot + 1;
p[tot].x = sx; p[tot].y = sy;
while (scanf ("%lf%lf", &x, &y) == 2) {
if (x == -1 && y == -1) {
for (int i=l; i<tot; ++i) {
double tim = get_cost (p[i], p[i+1], 40);
if (w[i][i+1] > tim) {
w[i][i+1] = w[i+1][i] = tim;
}
}
l = tot + 1;
continue;
}
p[++tot].x = x; p[tot].y = y;
}
p[++tot].x = ex; p[tot].y = ey;
for (int i=1; i<tot; ++i) {
for (int j=i+1; j<=tot; ++j) {
double tim = get_cost (p[i], p[j], 10);
if (w[i][j] > tim) {
w[i][j] = w[j][i] = tim;
}
}
}
Dijkstra (1);
printf ("%.0f\n", d[tot] * 60);
} return 0;
}
Dijkstra+计算几何 POJ 2502 Subway的更多相关文章
- 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 (Dijkstra 最短+建设规划)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6689 Accepted: 2176 Descriptio ...
- (简单) POJ 2502 Subway,Dijkstra。
Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...
- poj 2502 Subway【Dijkstra】
<题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...
- POJ 2502 Subway(迪杰斯特拉)
Subway Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6692 Accepted: 2177 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 ...
- POJ 2502 Subway ( 最短路 && 最短路建图 )
题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短 ...
随机推荐
- osgearth使用prjected投影
In projected mode, you have to specify a map profile (i.e. a map projection). You also need to tell ...
- WaxPatch中demo注意问题
问题一 https://github.com/mmin18/WaxPatch网址中提供的demo是可以运行,但是存在一个问题,如果把patch.zip换成自己的并且上传到自己的服务器(github), ...
- IT人学习方法论(二):学习误区
之前我们讨论了“学什么”的问题,今天我们来谈一谈“怎么学”的问题.磨刀不误砍柴工,我们要提高学习效率,首先需要找到自己学习方法上的误区. 一些常见的学习方法误区 1)资料导向型 现在就停止阅读这篇文章 ...
- python 中time模块使用
在开始之前,首先要说明这几点: 1.在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主 ...
- max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
sh- /etc/sysctl.conf vm.max_map_count = #在/etc/sysctl.conf追加上面一条 #并执行命令: sysctl -p
- 七牛:关于图片 EXIF 信息中旋转参数 Orientation 的理解
EXIF(Exchangeable Image File)是 “可交换图像文件” 的缩写,当中包含了专门为数码相机的照片而定制的元数据,可以记录数码照片的拍摄参数.缩略图及其他属性信息,简单来说,Ex ...
- I-number
以下是真坑爹题目: 此题必须输出前导零,否则永远a不了 I-number Time Limit: 5000MS Memory limit: 65536K 题目描述 The I-number of x ...
- JavaScript - 基本概念
相等操作符 == 和 != 是先转换再比较 === 和 !== 是直接比较,不经过转换 中文翻译上来说叫做相等和全等.类型转换简单的概括就是高级转低级,比如说布尔字符串转数字,对象取值再转.相等比较有 ...
- html5 基本布局+新标签+新选择器 + 线性渐变
html5 基本布局+新标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- thinkphp分页样式
html代码: <div class="pages">{$page}</div> css代码: .pages{ width:100.5%; text-ali ...