The 19th Zhejiang Provincial Collegiate Programming Contest
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output
Grammy is playing a boring racing game named Easy Gliding. The game's main content is to reach the destination as fast as possible by walking or gliding. The fastest player wins.
Each player controls a character on a two-dimensional plane. A character can walk at any moment with a speed of V1�1. Especially, when a character touches a gliding point, he/she can glide with a speed of V2�2 for the following 33 seconds. It is guaranteed that V1<V2�1<�2.
Now Grammy locates at point S� and she knows the coordinates of all the gliding points p1,p2,…,pn�1,�2,…,��. The goal is to reach point T� as fast as possible. Could you tell her the minimum time she has to spend to reach point T�?
Input
The first line contains one integer n� (1≤n≤10001≤�≤1000), denoting the number of gliding points.
The following n� lines describe the gliding points. The i�-th line contains two integers xi,yi��,�� (−1000000≤xi,yi≤1000000−1000000≤��,��≤1000000), representing the coordinates of the i�-th gliding point pi��.
The next line contains four integers Sx,Sy,Tx,Ty��,��,��,�� (−1000000≤Sx,Sy,Tx,Ty≤1000000−1000000≤��,��,��,��≤1000000), representing the coordinates of S� and T�.
The next line contains two integers V1,V2�1,�2 (1≤V1<V2≤10000001≤�1<�2≤1000000), representing the speed of walking and gliding.
Output
Output the minimum time Grammy has to spend to reach point T� in one line. Your answer will be considered correct if its absolute or relative error does not exceed 10−610−6.
Examples
input
2 2 1 0 3 0 0 4 0 10 11
output
0.400000000000
input
2 2 1 -2 0 0 0 4 0 1 2
output
3.354101966250
input
2 2 1 -2 0 0 0 4 0 1 10000
output
2.000600000000
用没有堆优化的dijkstra都能做得出的一道水题,把初始的x,y当作x[0],y[0]放进去,把终点当作x[n+1],y[n+1]放进去,套个for循环,注意初始点不能加速且这道题目是无向图
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
double x[N], y[N];
double sx, sy, tx, ty;
bool st[N];
double g[1100][1100];
double dist[N];
double v1, v2;
double d1;
double t1;
double t2;
double check(double a, double b, double c, double d)
{
return sqrt((double)(a - c) * (a - c) + (double)(b - d) * (b - d));
}
void dijkstra()
{
// memset(dist, 0x3f, sizeof dist);
dist[0] = 0;
for (int i = 0; i <= n + 1; i ++ )
{
int t = -1;
for (int j = 0; j <= n + 1; j ++ )
if (!st[j] && (t == -1 || dist[t] > dist[j]))
t = j;
for (int j = 0; j <= n + 1; j ++ )
dist[j] = min(dist[j], dist[t] + g[t][j]);
st[t] = true;
}
printf("%.12lf", dist[n + 1]);
}
int main()
{
cin >> n;
memset(dist, 127, sizeof dist);
memset(st, false, sizeof st);
memset(g, 127, sizeof g);
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
}
cin >> sx >> sy >> tx >> ty;
cin >> v1 >> v2;
x[0] = sx;
y[0] = sy;
x[n + 1] = tx;
y[n + 1] = ty;
for (int i = 0; i <= n + 1 ; i++)
{
for (int j = i + 1; j <= n + 1; j++)
{
d1 = check(x[i], y[i], x[j], y[j]);
if(i == 0 || j == 0)
{
t1 = d1 / v1;
}
else if (d1 / v2 > 3)
{
t1 = 3 + (d1 - 3 * v2) / v1;
}
else
{
t1 = d1 / v2;
}
g[i][j] = g[j][i] = t1;
}
}
dijkstra();
}