245人阅读 评论(0)

# Dig or Climb

.
.

.
.

.
.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

const int maXn = 2000;

struct Node {
double X, Y;
}a[maXn];
int n, m;
double vw, vc, X, Y, X1, Y1, X2, Y2, dist, f[maXn], up, down;
bool flag[maXn] = {0}, g[maXn] = {0};

double sqr(int X) {
return X*X;
}

double sqr(double X) {
return X*X;
}

int main() {
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);

scanf("%d", &n);
scanf("%lf %lf", &vw, &vc);
/*flag[1] = true;
g[1] = true;*/
for (int i = 1; i <= n; i++) {
scanf("%lf %lf", &a[i].X, &a[i].Y);
/*if (i > 1) {
if (a[i].Y <= a[i-1].Y) {
flag[i] = true;
flag[i-1] = false;
}
if (a[i].Y < a[i-1].Y) flag[i-1] = false;
if (a[i].Y < a[i-1].Y) {
g[i] = true;
g[i-1] = false;
}
}*/
}
for (int i = 1; i < n; i++) if (a[i].Y < a[i+1].Y) flag[i] = true;
for (int i = 2; i <= n; i++) if (a[i].Y < a[i-1].Y) g[i] = true;
f[1] = 0;
for (int i = 2; i <= n; i++) {
if (!g[i] || a[i-1].Y == a[i].Y) {
dist = sqrt(sqr(a[i].X-a[i-1].X)+sqr(a[i].Y-a[i-1].Y));
f[i] = f[i-1]+dist/vw;
} else {
dist = sqrt(sqr(a[i].X-a[i-1].X)+sqr(a[i].Y-a[i-1].Y));
f[i] = f[i-1]+dist/vw;
up = a[i-1].Y;
down = a[i].Y;
for (int j = i-2; j >= 1; j--) if (flag[j]) {
if (a[j].Y <= a[i].Y) {
X1 = a[j].X;
X2 = a[j+1].X;
Y1 = a[j].Y;
Y2 = a[j+1].Y;
Y = a[i].Y;
X = (Y-Y1)*(X2-X1)/(Y2-Y1)+X1;
f[i] = min(f[i], f[j]+(double(a[i].X)-X)*1.0/vc+sqrt(sqr(X-X1)+sqr(Y-Y1))/vw);
break;
} else if (a[j].Y < up && a[j].Y >= down) {
X1 = a[i-1].X;
X2 = a[i].X;
Y1 = a[i-1].Y;
Y2 = a[i].Y;
Y = a[j].Y;
X = (Y-Y2)*(X1-X2)/(Y1-Y2)+X2;
f[i] = min(f[i], f[j]+(X-double(a[j].X))*1.0/vc+sqrt(sqr(X-X2)+sqr(Y-Y2))/vw);
up = a[j].Y;
if (up == down) break;
}
}
}
}
printf("%.8lf\n", f[n]);

}


个人资料
等级：
访问量： 2万+
积分： 2395
排名： 1万+
文章分类
最新评论