2022-08-11 21:53:22 +08:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstring>
|
2022-08-11 21:46:01 +08:00
|
|
|
|
using namespace std;
|
2022-08-11 21:53:22 +08:00
|
|
|
|
const double inf = 1e100, EPS = 1e-6;
|
|
|
|
|
const int W = 20;
|
|
|
|
|
double l, now;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
int n;
|
2022-08-11 21:55:46 +08:00
|
|
|
|
//һ<><D2BB>ǽ
|
2022-08-11 21:46:01 +08:00
|
|
|
|
struct wall
|
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
double x, y[6], val[5];
|
2022-08-11 21:46:01 +08:00
|
|
|
|
} w[W];
|
2022-08-11 21:53:22 +08:00
|
|
|
|
// big bug:double->int
|
|
|
|
|
double length(double x1, double y1, double x2, double y2)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
double x = x1 - x2, y = y1 - y2;
|
|
|
|
|
return sqrt(x * x + y * y);
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
double cross(double x1, double y1, double x2, double y2)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
return x1 * y2 - x2 * y1;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
double same(double x0, double y0, double x3, double y3, double x1, double y1, double x2, double y2)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
double x = x3 - x0, y = y3 - y0; // y0->x0
|
|
|
|
|
return cross(x, y, x1 - x0, y1 - y0) * cross(x, y, x2 - x0, y2 - y0);
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
// WA double <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
|
2022-08-11 21:46:01 +08:00
|
|
|
|
int sign(double d)
|
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
if (fabs(d) < EPS)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
else
|
|
|
|
|
return d > 0 ? 1 : -1;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
bool ob(int li, int lj, int ri, int rj)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int i = li + 1; i < ri; i++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int j = 0; j <= 4; j += 2)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
// printf("(%.0lf,%.0lf)(%.0lf,%.0lf)/(%.0lf,%.0lf)(%.0lf,%.0lf):",w[i].x,w[i].y[j],w[i].x,w[i].y[j+1],w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj]);
|
|
|
|
|
// printf("[%.2lf/%.2lf]\n",same(w[i].x,w[i].y[j],w[i].x,w[i].y[j+1],w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj]),same(w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj],w[i].x,w[i].y[j],w[i].x,w[i].y[j+1]));
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>Ӧ<EFBFBD><D3A6>&&<26><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ|| ,<2C><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD>㽶
|
|
|
|
|
if (sign(same(w[i].x, w[i].y[j], w[i].x, w[i].y[j + 1], w[li].x, w[li].y[lj], w[ri].x, w[ri].y[rj])) < 0 && sign(same(w[li].x, w[li].y[lj], w[ri].x, w[ri].y[rj], w[i].x, w[i].y[j], w[i].x, w[i].y[j + 1])) < 0)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
void find(int ii, int jj)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int i = 0; i < ii; i++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int j = 1; j <= 4; j++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
l = length(w[ii].x, w[ii].y[jj], w[i].x, w[i].y[j]);
|
|
|
|
|
now = w[i].val[j] + l; // i j ii,jj<6A>㷴<EFBFBD><E3B7B4>
|
|
|
|
|
if (now < w[ii].val[jj] && ob(i, j, ii, jj))
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
w[ii].val[jj] = now;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
// printf("(%.0lf,%.0lf)(%.0lf,%.0lf):length:%.3lf,now:%.3lf<EFBFBD><EFBFBD>val:%.3lf\n",w[ii].x,w[ii].y[jj],w[i].x,w[i].y[j],l,now,w[ii].val[jj]);
|
|
|
|
|
if (i == 0)
|
|
|
|
|
break;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void doit()
|
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int i = 1; i <= n; i++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int j = 1; j <= 4; j++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
find(i, j);
|
|
|
|
|
if (i == n)
|
|
|
|
|
break;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
while (1)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
scanf("%d", &n);
|
2022-08-11 21:59:29 +08:00
|
|
|
|
if (n == -1)// <20><><EFBFBD><EFBFBD>
|
2022-08-11 21:53:22 +08:00
|
|
|
|
return 0;
|
|
|
|
|
memset(&w, 0, sizeof(wall) * (n + 1));
|
|
|
|
|
w[0].x = 0;
|
|
|
|
|
w[0].y[1] = 5;
|
|
|
|
|
w[0].val[1] = 0;
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
w[i].y[0] = 0;
|
|
|
|
|
w[i].y[5] = 10;
|
|
|
|
|
for (int j = 1; j <= 4; j++) //<2F>ִ<EFBFBD><D6B4><EFBFBD>i
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
w[i].val[j] = inf;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
for (int i = 1; i <= n; i++)
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
scanf("%lf", &w[i].x);
|
|
|
|
|
// cin>>w[i].x;
|
|
|
|
|
for (int j = 1; j <= 4; j++) // <20><><EFBFBD><EFBFBD>j
|
2022-08-11 21:46:01 +08:00
|
|
|
|
{
|
2022-08-11 21:53:22 +08:00
|
|
|
|
scanf("%lf", &w[i].y[j]);
|
|
|
|
|
// cin>>w[i].y[j];
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
w[++n].x = 10;
|
|
|
|
|
w[n].y[1] = 5;
|
|
|
|
|
w[n].val[1] = inf; // bug û<><C3BB>ֵ
|
2022-08-11 21:46:01 +08:00
|
|
|
|
doit();
|
2022-08-11 21:53:22 +08:00
|
|
|
|
printf("%.2lf\n", w[n].val[1]);
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|
2022-08-11 21:53:22 +08:00
|
|
|
|
return 0;
|
2022-08-11 21:46:01 +08:00
|
|
|
|
}
|