Description
Input
Output
Sample Input
0 0 10000 1000 0 200 5000 200 7000 200 -1 -1 2000 600 5000 600 10000 600 -1 -1
Sample Output
21
输入确实是坑。。我在本地都没有办法测试数据 硬是wa了数十次
floyd dijkstra spfa均可做
我觉得这题比较难的是建图。。 其实是因为自己不会建。。。
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "cmath"
using namespace std;
const int MAXN = 305;
struct node
{
/* data */
double x, y;
}point[MAXN];
double map[MAXN][MAXN], subv, walkv;
int n;
double dist(node a, node b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main(int argc, char const *argv[])
{
for(int i = 0; i < MAXN; ++i)
for(int j = 0; j < MAXN; ++j)
map[i][j] = -1;
subv = 40 * 1000.0 / 60;
walkv = 10 * 1000.0 / 60;
for(int i = 0; i < 2; ++i)
scanf("%lf%lf", &point[i].x, &point[i].y);
n = 2;
node last, now;
last.x = last.y = -1;
while(scanf("%lf%lf", &now.x, &now.y) != EOF) {
if(!(now.x == -1 && now.y == -1)) {
point[n++] = now;
if(!(last.x == -1 && last.y == -1))
map[n - 1][n - 2] = map[n - 2][n - 1] = dist(point[n - 1], point[n - 2]) / subv;
}
last = now;
}
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(map[i][j] == -1) map[i][j] = dist(point[i], point[j]) / walkv;
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
printf("%.0f\n", map[0][1]);
return 0;
}