C. Polynomial evaluation

    传统题 1000ms 256MiB

Polynomial evaluation

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem 2. Polynomial evaluation

Given a polynomial P(x)P(x) of degree nn

P(x)=a0+a1x++anxn=i=0naixi,P(x)=a_0+a_1x+\cdots+a_nx^n=\sum_{i=0}^na_ix^i,

we want to evaluate the polynomial at several points x0,x1,,xm1x_0, x_1,\cdots,x_{m-1}.

Input format

On the first line, a nonnegative integer nn, which is the degree of the polynomial.

On the second line, n+1n+1 numbers a0,a1,,ana_0,a_1,\cdots,a_n separated by space, which are the coefficients of the polynomial.

On the third line, a nonnegative integer mm.

Then mm lines follow, the ii-th of which is a number xi(i=0,1,,m1)x_i(i=0,1,\cdots,m-1).

Output format

mm lines, the ii-th of which (i=0,1,,m1i=0,1,\cdots,m-1) is a number P(xi)P\left(x_i\right), 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 n30n\leqslant 30. 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 P(xi)P\left(x_i\right) at a given point xix_i should be done using only one loop without call to standard library functions. Think about how to do this efficiently.

CS100 Spring2025 Homework 1

未认领
状态
已结束
题目
5
开始时间
2025-2-28 0:00
截止时间
2025-3-9 23:59
可延期
0 小时