L - Subway - POJ 2502
题意:在一个城市里,分布着若干条地铁线路,每条地铁线路有若干个站点,所有地铁的速度均为40km/h。现在你知道了出发地和终点的坐标,以及这些地铁 线路每个站点的坐标,你的步行速度为10km/h,且你到了地铁的任意一个站之后就刚好有地铁出发。问你从出发点到终点最少需要多少时间。
//////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std; const int maxn = 100005;
const int oo = 0xfffffff;
const double vs = 40*1000/60.0;//每分钟走多少米
const double vp = 10*1000/60.0; struct node
{
int u, v, next;
double c;//两点之间所需时间
}e[maxn];
struct point
{
int x, y;
}p[1005]; int nPoint, head[1005];
double dis[1005];
bool vis[1005]; double Len(point a, point b, double v)
{
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) / v;
}
void Add(int u, int v, double len, int k)
{
e[k].u = u;
e[k].v = v;
e[k].c = len;
e[k].next = head[u];
head[u] = k;
}
void spfa()
{
stack<int> sta;
sta.push(1); while(sta.size())
{
int i = sta.top();sta.pop();
vis[i] = false; for(int j=head[i]; j!=0; j=e[j].next)
{
int u = e[j].u, v = e[j].v;
double c = e[j].c; if(dis[u]+c < dis[v])
{
dis[v] = dis[u] + c;
if(vis[v] == false)
{
vis[v] = true;
sta.push(v);
}
}
}
}
} int main()
{
int i, j, flag=0, k=1; scanf("%d%d%d%d", &p[1].x, &p[1].y, &p[2].x, &p[2].y); nPoint = 3;
while(scanf("%d%d", &p[nPoint].x, &p[nPoint].y) != EOF)
{
if(p[nPoint].x != -1)
{
if(flag == 0)
flag = 1;
else
{
double c = Len(p[nPoint], p[nPoint-1], vs);
Add(nPoint, nPoint-1, c, k++);
Add(nPoint-1, nPoint, c, k++);
} nPoint++;
}
else
flag = 0;
} for(i=1; i<nPoint; i++)
for(j=i+1; j<=nPoint; j++)
{
double c = Len(p[i], p[j], vp);
Add(i, j, c, k++);
Add(j, i, c, k++);
} for(i=2; i<nPoint; i++)
dis[i] = oo; spfa(); printf("%.0f\n", dis[2]); return 0;
}
L - Subway - POJ 2502的更多相关文章
- Subway POJ 2502
题目链接: http://poj.org/problem?id=2502 题目大意: 你刚从一个安静的小镇搬到一个吵闹的大城市,所以你不能再骑自行车去上学了,只能乘坐地铁或者步行去上学.因为你不想迟到 ...
- Subway POJ - 2502 spfa
#include<cstdio> #include<cmath> #include<cstring> #include<cstring> #includ ...
- Subway POJ - 2502 最短路
题意:给出地铁线 起点和 终点 坐地铁速度为v2 走路为v1 求起点到终点的最短距离 (答案需要四舍五入这里坑了好久) 拿给出的地铁站点 和起点终点建边即可 然后跑个迪杰斯特拉 #inclu ...
- 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 ...
- L - Subway(最短路spfa)
L - Subway(最短路spfa) You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. In ...
- 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 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...
随机推荐
- JavaScript Window Screen
window.screen 对象包含有关用户屏幕的信息. Window Screen window.screen对象在编写时可以不使用 window 这个前缀. 一些属性: screen.availW ...
- phpcms(4) V9 栏目管理
phpcms V9框架系统后台管理之栏目管理,请参见下文的源码分析(添加栏目和修改栏目): 参照添加栏目的界面图示,便于对源代码的理解: <?php // 文件路径:phpcms/modul ...
- NPOI读写Excel0307
#region NPOI 操作 Excel 2007 /// <summary> /// 将Excel文件中的数据读出到DataTable中(xlsx) /// </summary& ...
- OpenGrok的安装
http://opengrok.github.io/OpenGrok/ Ubuntu环境下OpenGrok的安装及使用 http://www.linuxidc.com/Linux/2013-05/84 ...
- dictionary(字典)
dictionary(字典): 字典对象 字典是一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 1. dic={"n ...
- newman安装时遇到问题的解决
npm安装newman时系统提示需要安装.net framwork环境 通过查询文档安装visual studio express: 于是安装visual studio 2012 express. 安 ...
- C# 程序性能提升篇-2、类型(字段类型、class和struct)的错误定义所影响性能浅析
前景提要: 编写程序时,也许你不经意间,就不知不觉的定义了错误的类型,从而发生了额外的性能消耗,从而降低了效率,不要说就发生那么一次两次,如果说是程序中发生了循环.网络程序(不断请求处理的)等这些时候 ...
- IOS“多继承”
转自念茜的博客: 当单继承不够用,很难为问题域建模时,我们通常都会直接想到多继承.多继承是从多余一个直接基类派生类的能力,可以更加直接地为应用程序建模.但是Objective-C不支持多继承,由于消息 ...
- python 性能鸡汤
转载自:http://www.oschina.net/question/1579_45822 1:使用内建函数input() int() isinstance() issubclass() iter( ...
- ECMAScript 6 模块简介
任何平台的其中一个重要特性,除了需要支持代码库外就是模块.直到现在,Javascript还不支持原生的模块化.结果是,各种解决方案都将模块添加到类库中,比如CommonJS modules(部分由no ...