题目传送门

题意:列车上行驶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的更多相关文章

  1. 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 ...

  2. POJ 2502 - Subway Dijkstra堆优化试水

    做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 ...

  3. POJ 2502 Subway (Dijkstra 最短+建设规划)

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Descriptio ...

  4. (简单) POJ 2502 Subway,Dijkstra。

    Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of ...

  5. poj 2502 Subway【Dijkstra】

    <题目链接> 题目大意: 某学生从家到学校之间有N(<200)条地铁,这个学生可以在任意站点上下车,无论何时都能赶上地铁,可以从一条地铁的任意一站到另一条地跌的任意一站,学生步行速度 ...

  6. POJ 2502 Subway(迪杰斯特拉)

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

  7. POJ 2502 Subway

    Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4928   Accepted: 1602 Descriptio ...

  8. POJ 2502 Subway (最短路)

    Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

  9. POJ 2502 Subway ( 最短路 && 最短路建图 )

    题意 : 给出二维平面上的两个点代表起点以及终点,接下来给出若干条地铁线路,除了在地铁线路上行进的速度为 40km/h 其余的点到点间都只能用过步行且其速度为 10km/h ,现问你从起点到终点的最短 ...

随机推荐

  1. Alcatraz安装在xcode7失败执行下面代码

    1.步奏rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin 2.步奏 rm ...

  2. iOS中UITableView的一些设置

    不可滑动: ? 1 tableView.userInteractionEnabled = NO; 也可以在storyboard中的userInteractionEnable属性设置 显示导向箭头: ? ...

  3. September 11th 2016 Week 38th Sunday

    Nothing happens unless first a dream. 一切始于梦想. When everything seems to be going against you, remembe ...

  4. QT_SVG格式图片浏览器_源代码下载_详细注释

    源代码链接: http://pan.baidu.com/s/1pKA5Vcv 密码: ib2x 注:SVG格式图片特点: 1. 文件小 2. 图像中文字独立于图像, 可以编辑,可搜索. 3.没有字体限 ...

  5. mysql常用表/视图管理语句

    查看所有表  show tables; 查看表/视图结构 desc 表名/视图名: 查看建表过程  show create table 表名: 查看建视图过程 show create view 视图名 ...

  6. Android Programming: Pushing the Limits -- Chapter 5: Android User Interface Operations

    多屏幕 自定义View 多屏幕 @.Android 4.2 开始支持多屏幕. @.举例: public class SecondDisplayDemo extends Activity { priva ...

  7. mysql可以用这种方式<<! 输入内容 ! 做成脚本

    以这种文件式做交接NB!!!!! [root@NB test]# mysql -uroot -p$passwd <<! > use mysql > select user,ho ...

  8. weblogic监控

    http://wenku.baidu.com/link?url=tQPQ-dgm7NOkEGj_vemwtsPd6TJ6W3x6_0UBLgw61N982SwPlz-QFxqncsmPGqHwJAEF ...

  9. Delphi的面向对象编程基础笔记

    1.面向对象.一门面向对象的编程语言至少要实现以下三个OOP的概念 封装:把相关的数据和代码结合在一起,并隐藏细节.封装的好处是利用程序的模块化,并把代码和其他代码分开 继承:是指一个新的类能够从父类 ...

  10. .NET MVC4 数据验证Model(二)

      一.概述 MVC分为ViewModel.Control.View,对数据的封装MVC做的很好,确实是不错的WEB框架,针对MVC的ViewModel封装的也是相当的不错,最近做一个MVC的项目,采 ...