E |
Ensuring Victory |
Since
your team always loses in football, you are now planning to tip the balance in
your favor by using a specially designed ball. To this end you construct many
balls of varying designs and from several different materials and ask your team
to try them out.
As
expected, the feedback is rather random and inconsistent, with some players
liking some of the balls while others not liking those very same ones. Since
that is not helping, you decide on a more objective method of finding out which
ones are the best. You conduct a series of experiments and observe the behavior
of each of these balls when kicked. After the trials, you have worked out for
each ball an exact formula that gives the ball's position t seconds after being
kicked.
Using
that, you can determine the behavior of the balls in an actual game accurately
on paper. You are interested in knowing the position of the ball as well as the
speed at which it is travelling at specific moments in time. The position
(which is basically its Euclidean distance from a certain point) is found by
simply computing the value from the formula. The speed of the ball is defined
as the rate of change of distance with time at that moment (i.e. the derivative
of distance with respect to time). Since there are a lot of different balls,
you want to automate this process and get the results before the tournament
starts.
Unfortunately,
your football team is not any better at computing than they are at football
(you must have guessed that already). So it falls again on you to solve this
problem.
Input
Input
file will consist of a number of test cases (<=50). Each test case consists
of two lines. The first line is a simple algebraic expression which gives the
distance covered by the ball in terms of t.
The length of this expression can be at most 200. It will consist of numbers
and the operators '*' and '+' and the variable t. The numbers will all be fractional numbers of the format “X/Y”,
where X is the numerator and Y the denominator. X and Y in this line will never
be negative and Y will never be 0. The expression might also contain
parentheses ( '(' and ')' ) to force precedence. The usual rules and precedence
of arithmetic apply when using the formula to compute the answer. The next line
consists of a single fractional number on a line by itself. It is the value of
t. This is also of the form “X/Y”, but here X and Y can also be negative. No
input line will be greater than 150 characters in length. There will be no
extra whitespace or any blank lines in input.
Output
Output
will consist of exactly as many lines as there are cases. For each case, print
a line of the form “Case #C: A B”. C is the case (starting from 1), while A and
B are fractional numbers in their simplest form. A is the distance of the ball
and B is its speed at time t. Both numbers are also of the form “X/Y”. If the
value is negative, print it as “-X/Y”. Zero should be printed as “0/1”.
Note:
Sample Input |
Sample Output |
((t*t)+2/1)
1/2
((t+t)*2/1)
1/2
(t*1/2)+(t*1/3)
1/4 |
Case
#1: 9/4 1/1 Case
#2: 2/1 4/1 Case
#3: 5/24 5/6 |
Problemsetter: Muntasir Khan, Special Thanks: Samee Zahur,
Jane Alam Jan