Laplace interpolation,
The proof of existence and uniqueness will be supplemented later ....
Laplace Interpolation
Laplace interpolation, emmmm, with a very high name: joy:
What applications does it have?
We have talked about it in FFT.
Set $ n-1 $ subpolynomial
$ Y = \ sum _ {I = 0} ^ {n-1} a_ I x ^ I $
There is an obvious conclusion: If $ n $ is given with different vertices $ (x, y) $, the $ n-1 $ subpolynomial is uniquely identified.
If the $ n $ points are given,
With the use of Laplace interpolation, you can calculate the value of a certain item in the time of $ O (n) $, or at $ O (n ^ 2) $ calculate the corresponding $ y for the given $ x $ in time complexity.
So how to calculate it?
Formula
Don't worry about it. Just give the formula directly. How can this formula be provided later?
For $ n-1 $ subpolynomials, $ n $ (x, y) $ is given.
For the given $ x $, the value of item $ I $ is
$ L (I) = y_ I \ prod _ {j = 1, j \ neq I} ^ {n} \ dfrac {x-x_j} {x_i-x_j} $
The corresponding $ y $ is
$ Y = \ sum _ {I = 1} ^ {n} l (I) $
$ = \ Sum _ {I = 1} ^ {n} y_ I \ prod _ {j = 1, j \ neq I} ^ {n} \ dfrac {x-x_j} {x_i-x_j} $
This formula can be used for calculation.
Code
# Include <cstdio> int x [1001], y [1001]; int N, ans = 0; int main () {scanf ("% d", & N ); for (int I = 1; I <= N; I ++) scanf ("% d", & x [I], & y [I]); int X; // The x scanf ("% d", & X) to be obtained; for (int I = 1; I <= N; I ++) {int tmp = y [I]; for (int j = 1; j <= N; j ++) {if (I = j) continue; tmp = tmp * (X-x [j])/(x [I]-x [j]);} ans + = tmp;} printf ("% d ", ans); return 0 ;}