SP22320 POLYDRAW - Polynomial Drawing

Description

If you like polynomials, you might have solved problems like [POLEVAL](../../problems/POLEVAL/), [POLYNOM](../../problems/POLYNOM/) or [POLYTABL](../../problems/POLYTABL/). But if you are especially interested in graphs of polynomials, here is the problem for you: Given a polynomial, your task is to create an image file of its graph.

Input Format

Input starts with a positive integer t

Output Format

For every testcase you have to generate a compressed version of a [pgm-imagefile](http://en.wikipedia.org/wiki/Netpbm_format#PGM_example) (type P2) showing the polynomial's graph. The first line of output is the pgm-header printed in a single line: "P2 \[w\] \[h\] 2", where \[w\] and \[h\] have to be replaced by the width and height of the image (see example below). The following one to three lines contain the polynomial's term and drawing interval exactly as given in the input. As this would make the pgm-file invalid, each of these lines has to start with a leading "#" followed by a whitespace. After that h lines of data follow. Every line consists of w values separated by single spaces. Each value is either 0 (black), 1 (gray) or 2 (white) and represents a single pixel of the image. The width of the image is derived from the given interval \[a;b\]. For all images we take 20px as size of one unit in x- and y-direction. For every pixel in horizontal direction calculate the correponding y-value and mark that point of the graph by a black pixel. If a calculated y-value does not exactly match to the position of a pixel, you always choose the pixel with least vertical distance. If there is more than one of these pixels, take the pixel that represents the lower value. No (intermediate) value will have an absolute value larger than 10¹⁸, if calculations are done carefully. The height of the image depends on the minimum and maximum values of the polynomial in the given drawing interval, where "value" refers to the y-value of the drawn point, not to the exact y-value of the corresponding x-value if that differs. The range for the y-values reaches from the largest integer smaller than the minimum value to the smallest integer value larger than the maximum value. So, if y $ _{min} $ =-3.2 and y $ _{max} $ =4 the range for the y-values reaches from -4 to 5 and results in h=181. The value of h will always be less than 1000. The background of the image is white. All lattice points of the coordinate system are marked with a single gray pixel. If the given x-intervall or the calculated y-range include zero, the x- and/or y-axis are drawn as gray line with 1px linewidth. After drawing the coordinate system including the grid, the graph of the polynomial is drawn. For every pixel in x-direction the corresponding y-value is calculated and the resulting point drawn as a single black pixel. As this valid pgm image representation produces rather large image files, it has to be printed in **egg-format** (_encoded grayscale graphics_), which uses a two-pass run length encoding compression. The header gets an additional information about the egg-format: The pgm header line is followed by a single space and an indication of the format "(egg)". The second line of the egg-file is a new additional comment containing information about compression rate: "# Compression: xx.xx%". The compression rate is calculated as "1-(egg-size/pgm-size)", where "size" refers to the pure image size without header, comments and newline characters. The compression rate has to be denoted as percentage with an accurary of two digits after the decimal point. In _pass one_, every row is encoded. First all spaces between the pixel values are removed. Then every consecutive sequence of the same color that is longer than three pixels is replaced by brackets including the total value of consecutive pixels of that color. For identification of color, different typs of brackets are used: round brackets for white pixels, braces for gray pixels and square brackets for black pixels. **Example**: 0 0 0 0 0 2 2 2 2 1 1 1 2 2 1 1 1 1 1 1 1 is encoded to \[5\](4)11122{7} In _pass two_ consecutive rows are encoded, if there are (at least two) consecutive identical rows. In that case, only the first row is used, followed by the total number of identical consecutive rows in angle brackets "< >". ![](http://didax.heliohost.org/eggviewer/polydraw-example-3x.png) Unfortunately the egg-format is not widely spread, in fact there is actually no image viewer that is able to handle images in egg-format, except the [online egg-viewer](http://didax.heliohost.org/eggviewer). So, if you want to make your egg-files visible, I recommend the egg-viewer: just paste your egg data and make the image visible. The figure on the right shows the graph of the example output (scaled by a factor of 3 for better recognition of single pixels). _Note: Print a blank line after every testcase except the last one._