Polynomial evaluation
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Problem 2. Polynomial evaluation
Given a polynomial of degree
we want to evaluate the polynomial at several points .
Input format
On the first line, a nonnegative integer , which is the degree of the polynomial.
On the second line, numbers separated by space, which are the coefficients of the polynomial.
On the third line, a nonnegative integer .
Then lines follow, the -th of which is a number .
Output format
lines, the -th of which () is a number , rounded to three decimal places.
Example
Input
2
-0.5 1 2.5
5
0
-6.6
1000
-1
32
Output
-0.500
101.800
2500999.500
1.000
2591.500
Notes
It is guaranteed that . An array is enough to store the coefficients. Do not use heap memory.
Your program will not be compiled and linked against the math library, so do not use the functions in <math.h>
.
The evaluation of at a given point should be done using only one loop without call to standard library functions. Think about how to do this efficiently.