首页 技术 正文
技术 2022年11月18日
0 收藏 683 点赞 3,183 浏览 3031 个字

By the Underground or by Foot?

Time limit: 1.0 second
Memory limit: 64 MBImagine 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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290