By the Underground or by Foot?

Time limit: 1.0 second
Memory limit: 64 MB
Imagine yourself in a big city. You want to get from point A to point B.
To do that you may move by foot or use the underground. Moving by the
underground is faster but you may enter and exit it only at the
stations. To save your time you decided to write a program to find the
fastest route.

Input

The
first line contains two floating point numbers. First of them is the
speed of traveling by foot. The second one is the speed of traveling by
the underground. The second speed is always greater than the first one.
Then description of the underground follows. It starts with an integer number N in the first line. It is the number of the underground stations. You may assume that N is not greater than 200. The following N lines contain two floating point numbers each (i-th line contains the coordinates of i-th
station). Then the description of the connections between stations
follows. Each connection is determined by the pair of integers, i.e. by
the numbers of connected stations. The list of connections is terminates
with a pair of zeroes. We assume that all the connections are straight.
So the time we need to travel between stations is equal to the distance
between stations divided by the speed of traveling by the underground.
It
should be mentioned also that entering and exiting the underground and
changing trains are possible at the stations only and takes no time.
At last the coordinates of the points A and B are given, tha pair of coordinates in a line.

Output

The first line should contain the minimal time needed to get from the point A to the point B. Time should be given with the precision of 10−6.
The second line describes the use of the underground while traveling.
It starts with the number of visited stations with tha following list of
visited stations in the order they should be visited.

Sample

input output
1 100
4
0 0
1 0
9 0
9 9
1 2
1 3
2 4
0 0
10 10
10 0
2.6346295
4 4 2 1 3
Problem Author: Alexander Klepinin
【分析】最短路,SPFA。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int n,m,k=;
double a,b;
int vis[N],pre[N];
double w[N][N],d[N];
char str[];
bool flag=false;
struct man{
double x,y;
}point[N];
void spfa()
{
d[]=;
vis[]=;
queue<int>q;
q.push();
while(!q.empty()){
int t=q.front();q.pop();
vis[t]=;
for(int i=;i<=n+;i++){
if(d[i]>d[t]+w[t][i]){
d[i]=d[t]+w[t][i];
pre[i]=t;
if(!vis[i])q.push(i),vis[i]=;
}
}
}
}
int main() {
for(int i=;i<N;i++){
d[i]=;
for(int j=;j<N;j++){
w[i][j]=;
}
}
scanf("%lf%lf",&a,&b);
scanf("%d",&n);
int u,v; for(int i=;i<=n;i++){
scanf("%lf%lf",&point[i].x,&point[i].y);
}
while(~scanf("%d%d",&u,&v)&&u&&v){
double s=sqrt((point[u].x-point[v].x)*(point[u].x-point[v].x)+(point[u].y-point[v].y)*(point[u].y-point[v].y));
w[u][v]=w[v][u]=s/b;
}
scanf("%lf%lf%lf%lf",&point[].x,&point[].y,&point[n+].x,&point[n+].y);
for(int i=;i<=n+;i++){
for(int j=i+;j<=n+;j++){
if(w[i][j]<)continue;
double s=sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+(point[i].y-point[j].y)*(point[i].y-point[j].y));
w[i][j]=w[i][j]=s/a;
}
}
spfa();
printf("%.7lf\n",d[n+]);
stack<int>p;
for(int i=n+;pre[i];i=pre[i]){
p.push(pre[i]);
}
printf("%d",p.size());
while(!p.empty())printf(" %d",p.top()),p.pop();
return ;
}

URAL 1205 By the Underground or by Foot?(SPFA)的更多相关文章

  1. 1205: 求一元二次方程的实数根(C)

    一.题目 acm.wust.edu.cn/problem.php?id=1205&soj=0 二.分析 一元二次方程有三个系数a.b.c,两个根x1.x2,以及d(德尔塔): a.b.c均为实 ...

  2. 1205. By the Underground or by Foot?(spfa)

    1205 简单题 有一些小细节 两个站可能不相连 但是可以走过去 #include <iostream> #include<cstdio> #include<cstrin ...

  3. URAL 1104 Don’t Ask Woman about Her Age(数论)

    题目链接 题意 : 给你一个数,未知进制,然后让你从2到36进制中找出一个最小的进制K,满足给你的这个数作为k进制时能够整除k-1. 思路 : 有一个公式,(a*b^n)mod(b-1)=a: 给定你 ...

  4. URAL 1099 Work scheduling 一般图的最大匹配 带花树算法(模板)

    R - Work scheduling Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  5. URAL 1876 Centipede's Morning(数学)

    A centipede has 40 left feet and 40 right feet. It keeps a left slippers and b right slippers under ...

  6. URAL 1549 Another Japanese Puzzle(构造)

    题目大意 构造一条闭合路线,使得路线不能相交,并且走直线的步数小于等于 S,转弯(左转和右转)的步数小于等于 T.(0≤S,T≤1000) 求一条最长的路线 做法分析 注意到,因为要求路线闭合,那么转 ...

  7. URAL 1139 City Blocks(数论)

    The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...

  8. URAL 1208 Legendary Teams Contest(DFS)

    Legendary Teams Contest Time limit: 1.0 secondMemory limit: 64 MB Nothing makes as old as years. A l ...

  9. URAL 1119. Metro(BFS)

    点我看题目 题意  : 这个人在左下角,地铁在右上角,由很多格子组成的地图,每一条边都是一条路,每一条边都是100米.还有的可以走对角线,问你从起点到终点最短是多少. 思路 : 其实我想说一下,,,, ...

随机推荐

  1. python解无忧公主的数学时间编程题001.py

    python解无忧公主的数学时间编程题001.py """ python解无忧公主的数学时间编程题001.py http://mp.weixin.qq.com/s?__b ...

  2. AJAX笔记

    浏览器脚本——AJAX AJAX =  异步的 JavaScript 和 XML(Asynchronous JavaScript and XML). 是一种新的技术,它可以创建更好.更快且交互性更强的 ...

  3. win8系统 host文件无法修改解决之道

    host文件,路径为:C:\windows\system32\drivers\etc\hosts 方法/步骤: 方法1:用notepad++打开host文件,修改和保存 方法2:(1)首先用管理管权限 ...

  4. hdu 2055

    PS:上课的时候敲的..这道题简单..一次AC,不多说了.. 代码: #include "stdio.h"int main(){ int i,n,y; char x,a[26],b ...

  5. 2016 - 1 - 20 runloop学习

    一:Runloop基本知识 1.本质就是运行循环 2.基本作用: 2.1保证程序持续运行 2.2处理APP中的各种事件:触摸,定时器,selector... 2.3节省CPU资源,系统程序性能:它会让 ...

  6. Virtual Friend Function

    一般而言,友元作为一种紧耦合的设计,被视作类的一部分.一个经典的应用就是关于类的序列化和反序列化. class A { friend ostream& operator<<(ost ...

  7. java 集合归类

    对java的集合一直是停留在使用的角度,没有进行系统的归纳,趁现在比较空闲,归纳一下. 1  集合的层次关系 最顶层的有三个集合,其中一个类,两个接口, 一个类是Arrays,两个接口是Collect ...

  8. RFID Hacking③:使用ProxMark3嗅探银行闪付卡信息

    0×00 前言 RFID是Radio Frequency Identification的缩写,术语为射频识别,俗称电子标签.按照工作频率的不同,RFID标签可以分为低频(LF).高频(HF).超高频( ...

  9. bootstrap菜单完美解决---原创

    由于bootstrap的各方优点,偶的“点金项目细化分包管理平台”决定采用它.但在使用中遇到了一些问题,比如菜单的问题,这个菜单是用的一个JQuery的一个效果,点击后,所点击的链接处的class要加 ...

  10. 看了这篇文章,Java编程速度我都惊呆了

    熟记于心,打遍天下,(开始装了) 保存 Ctrl+s                    (这个就不用解释了吧!!!!) 注释代码 Ctrl+/ 取消注释 Ctrl+/代码辅助 Alt+/ 快速修复 ...