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 ,现问你从起点到终点的最短 ...
随机推荐
- mac VPN配置
来自: http://www.eefocus.com/Kevin/blog/11-09/230878_53c71.html RSA的SecurID长的是这个样子滴: Mac里面,可以设置VPN, 方法 ...
- 异常处理__try{}__except(EXCEPTION_EXECUTE_HANDLER){}
在一个函数中不能混合使用 try{}catch(CException *e){} 与 __try{}__except(EXCEPTION_EXECUTE_HANDLER){} 编译时报错 error ...
- October 13th 2016 Week 42nd Thursday
If the world seems cold to you, kindle fires to warm it. 若世界以寒相待,请点燃火堆以温暖相报. Kindle fires to warm th ...
- @ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4 "/" $NF}'中"[ :]+" 是什么意思?@
http://blog.csdn.net/zhuying_linux/article/details/6822987
- Redis笔记(七)Java实现Redis消息队列
这里我使用Redis的发布.订阅功能实现简单的消息队列,基本的命令有publish.subscribe等. 在Jedis中,有对应的java方法,但是只能发布字符串消息.为了传输对象,需要将对象进行序 ...
- Delphi中的各种字符串、String、PChar、Char数组
参考博客:http://www.cnblogs.com/pchmonster/archive/2011/12/14/2287686.html 其中的所有代码均在Delphi7下测试通过. Delphi ...
- 【翻译十三】java-并发之饥饿与活锁
Starvation and Livelock Starvation and livelock are much less common a problem than deadlock, but ar ...
- gdo图形引擎中的旋转角
横滚角(Roll) bank.roll 绕y轴 z轴正向为起点逆时针方向:往左为正,往右为负,水平时为0:有效范围:-180度-180度 注:下图是从飞机的尾部-->头部方向观察所得 俯仰角( ...
- SQL Server 2014 BI新特性(一)五个关键点带你了解Excel下的Data Explorer
Data Explorer是即将发布的SQL Server 2014里的一个新特性,借助这个特性讲使企业中的自助式的商业智能变得更加的灵活,从而也降低了商业智能的门槛. 此文是在微软商业智能官方博客里 ...
- JS获取form表单的所有输入值
function getFormQueryString(frmID) { var frmID=document.getElementById(frmID); var i,queryString = & ...