CARL - Carl
Professor Octastichs has invented a new programming language, Carl. An expression in Carl may be a positive or negative integer, or may be of the form (p e1 e2) where p is a real number between 0 and 1 (inclusive) and e1 and e2 are Carl expressions. An integer represents itself and (p e1 e2) represents x + y where x is the value of e1 and y is the value of e2 with probability p, otherwise it represents x - y.
Given a Carl expression, what is its expected value?
Input
Input consists of several Carl expressions, one per line, followed by a line containing ().
Output
For each expression, output its expected value to two decimal places.
Score
Score is the length of your source program.
Example
Input: 7 (.5 3 9) () Output: 7.00 3.00
hide comments
Ouditchya Sinha:
2013-07-21 12:25:48
Nice problem! For those getting WA, use doubles. A sample test case for you-
|
|
legrand:
2012-11-05 18:50:18
always wa, but working with my testcases. Are there tricky inputs? |
|
__KIRA__:
2012-02-12 11:46:41
@xiling why wa always any tricky inputs??
|
Added by: | Fudan University Problem Setters |
Date: | 2008-04-19 |
Time limit: | 0.200s |
Source limit: | 512B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: C99 ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Waterloo Local Contest |