#P8924. Plotting a Polynomial Function
Plotting a Polynomial Function
Plotting a Polynomial Function
Given a polynomial function defined as
$$f(x)=a_kx^k+a_{k-1}x^{k-1}+\cdots+a_1x+a_0,$$draw its graph on an n × m grid. The x-coordinate ranges over [0, n-1] and the y-coordinate (i.e. the value of f(x)) must lie in the range [0, m-1].
For each integer x in [0, n-1], if the computed f(x) is an integer within [0, m-1], mark that grid cell with a *
. Otherwise, leave it as .
. The grid is printed such that columns correspond to x-values from left (x = 0) to right (x = n-1), and rows correspond to y-values from bottom (y = 0) to top (y = m-1).
inputFormat
The input consists of two lines:
- The first line contains three integers:
n
,m
, andk
separated by spaces. Here,n
andm
represent the dimensions of the grid, andk
is the degree of the polynomial. - The second line contains
k+1
integers:ak ak-1 ... a0
, which are the coefficients of the polynomial.
The polynomial is defined as:
$$f(x)=a_kx^k+a_{k-1}x^{k-1}+\cdots+a_1x+a_0.$$Only integer values of x in the range [0, n-1] are considered.
outputFormat
Output the grid as m
lines, each consisting of n
characters. The grid represents a coordinate system where the leftmost column corresponds to x = 0 and the rightmost to x = n-1, and the bottom row corresponds to y = 0 while the top row corresponds to y = m-1.
For each integer x, if f(x) is an integer within [0, m-1], mark the cell at column (x+1) (from left) and row (f(x)+1) (from bottom) with a *
; otherwise, the cell should contain a .
.
sample
10 10 2
1 0 0
...*......
..........
..........
..........
..........
.........
..........
..........
.........
*.........
</p>