题目大意:
注释代码:
无注释代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#define INF 1E15
#define MAXN 202
#define V_W 10
#define V_S 40
using namespace std;
struct Point {
int x, y;
friend istream &
operator>>(istream &is, Point &p) {
is >> p.x >> p.y;
return is;
}
int
POW(int a) { return a * a; }
double
operator^(Point &oth) {
return sqrt( (double)POW( x - oth.x ) + POW( y - oth.y ) );
}
};
struct Node {
int u;
double d;
Node(void) {}
Node(int uu, double dd) : u(uu), d(dd) {}
bool
operator<(const Node &oth)
const {
return d > oth.d;
}
};
double g[MAXN][MAXN];
Point p[MAXN];
double d[MAXN];
bool vis[MAXN];
priority_queue<Node> heap;
double
dij(int n) {
int u, v;
int i;
Node node;
for ( i = 1; i < n; i++ ) d[i] = INF;
heap.push(Node(0, 0));
while ( !heap.empty() ) {
node = heap.top();
heap.pop();
if ( 1 == ( u = node.u ) ) return d[1];
if ( vis[u] ) continue;
vis[u] = true;
for ( v = 1; v < n; v++ )
if ( !vis[v] && d[u] + g[u][v] < d[v] ) {
d[v] = d[u] + g[u][v];
heap.push(Node(v, d[v]));
}
}
return -1.0;
}
int
main() {
int n;
int x, y;
int i, j;
cin >> p[0] >> p[1];
n = 1;
while ( cin >> p[++n] ) {
while ( ( cin >> p[++n] ), p[n].x != -1 )
g[n][n - 1] = g[n - 1][n] = ( p[n] ^ p[n - 1] ) * 3 / ( V_S * 50 );
n--;
}
for ( i = 0; i < n; i++ )
for ( j = i + 1; j < n; j++ )
if ( !g[i][j] )
g[i][j] = g[j][i] = ( p[i] ^ p[j] ) * 3 / ( V_W * 50 );
printf("%.0lf\n", dij(n));
return 0;
}