#include<iostream>
using namespace std;
double Lagrange(double x[], double y[], double t, int n)
{
double fx = 0;
int start, end;
if (x[0] > t)
{
start = 0;
end = 7;
}
else if (x[n - 1] < t)
{
start = n - 7;
end = n;
}
else
{
for (int i = 0; i < n; i++)
{
if (x[i]<t && x[i + 1]>t)
{
start = i - 3;
end = i + 4;
if (start < 0)
{
start = 0;
end = 7;
}
if (end > n - 1)
{
start = n - 7;
end = 0;
}
}
}
}
double xx[8], yy[8];
for (int i = 0; i < 8; i++)
{
xx[i] = x[start + i];
yy[i] = y[start + i];
}
for (int i = 0; i < 8; i++)
{
double tmp = 1;
for (int j = 0; j < i; j++)
tmp = tmp * (t - xx[j]) / (xx[i] - xx[j]);
for (int j = i + 1; j < 8; j++)
tmp = tmp * (t - xx[j]) / (xx[i] - xx[j]);
fx += tmp * yy[i];
}
return fx;
}
int main()
{
int n;
double t;
cin >> n;
cin >> t;
double* x = new double[n];
double* y = new double[n];
for (int i = 0; i < n; i++)
{
cin >> *(x + i);
cin >> *(y + i);
}
cout << Lagrange(x, y, t, n);
/*
20
0.13
0.10 0.1103329
0.15 0.1736223
0.20 0.2426552
0.25 0.3176729
0.30 0.3989105
0.35 0.4865951
0.40 0.5809439
0.45 0.6821617
0.50 0.7904390
0.55 0.9059492
0.60 1.0288456
0.65 1.1592592
0.70 1.2972951
0.75 1.4430292
0.80 1.5965053
0.85 1.7577308
0.90 1.9266733
0.95 2.1032653
1.00 2.2873552
1.05 2.4787929
*/
}
最终运算结果