PLOT1 - Plotting functions (variation)

no tags 

Given a function y=f(x) in RPN-notation plot it with stars (*) and then (!) its derivation with crosses (+) for 0<=x<=20 with Δx=1 in a diagram with 21*21 points (0<=x,y<=20). Empty fields are marked with dots (.). For plotting the real number y should be rounded to integer (-0.5 -> -1, -0.4 -> 0, 0.4 -> 0, 0.5 -> 1). The function and its derivation are continuous between 0 and 20.
The function definition uses only the following characters: 0123456789x.+-*/^
'^' means 'power of'. Items are separated by space.

Input

In the first line the number N of functions, then N lines with one function.

Output

The plot of each function and its derivation in 21 lines.

Example

Input:
1
x 1 - Output: .....................
....................*
...................*.
..................*..
.................*...
................*....
...............*.....
..............*......
.............*.......
............*........
...........*.........
..........*..........
.........*...........
........*............
.......*.............
......*..............
.....*...............
....*................
...*.................
+++++++++++++++++++++
.*...................

hide comments
HWK: 2011-08-13 19:51:14

@stassats: Check the 'power' and the derivations. ;-)

Last edit: 2011-08-13 20:01:45
HWK: 2011-03-21 20:47:05

Is the scoring now correct?

:D: 2011-03-21 20:47:05

There seems to be some problem with the scoring. I think it is counted as challenge because of adding the score (my points don't add up). Maybe AC/Fail type would be enough here?

EDIT: Yes, thanks!

Last edit: 2011-03-20 15:43:35
HWK: 2011-03-21 20:47:05

Right! "Half away from zero", that's its name.
BTW I didn't expect the first solution in C++.

Last edit: 2011-03-20 09:01:08
:D: 2011-03-21 20:47:05

Yay, solved at first try :) Was expecting some rounding issues. BTW did the rounding method was supposed to be "half away from zero"?

HWK: 2011-03-21 20:47:05

I've chosen the standard judge knowing that a wrong plot could be accepted. But there are a lot of tasks where this is possible and I think that this wouldn't make the solution much easier.
But for clarity I'll change spaces to dots as :D suggested.

numerix: 2011-03-21 20:47:05

@HWK: Spaces do not matter if you use the standard judge. If the "exact judge" is used (and that's what should be done here), any character matters. As :D pointed out: Using the standard judge for this problem makes it possible to get AC even with a wrong plot.

:D: 2011-03-21 20:47:05

If your're using the standard SPOJ judge and don't use any padding like dots, the testing will be very weak. For example this plot image (dots used instead of spaces for clarity):

.*.
.*.
.*.

will be judged as the same as this:

*..
..*
*..

You can check, I'm pretty sure of it :) Using a non-whitespace background would automatically resolve this issue.

EDIT: THANKS!

Last edit: 2011-03-15 18:21:05
HWK: 2011-03-21 20:47:05

In the real output data there are trailing spaces. It seems that they are lost on the website. (I've changed it.)
But white space doesn't really matter. Look here: http://www.spoj.pl/SHORTEN/embed/rules/
Thus I think I don't have to replace spaces with dots. In my opinion the plot looks better with spaces.

Last edit: 2011-03-15 12:49:28
:D: 2011-03-21 20:47:05

In the output there are trailing whitespaces to form a rectangle, but not after the last line. What exactly is the output format?

EDIT: I would suggest filling the whole output plotting area with dots '.'. Whitespaces will cause a lot of unnecessary issues.

Last edit: 2011-03-15 07:50:45

Added by:HWK
Date:2011-03-02
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64