SEAGM2 - Editorial

I used the BigDecimal class in java and got it accepted. Here’s the link to my solution CodeChef: Practical coding for everyone .

I have used the BigDecimal class in java. Here is the link to my solution. CodeChef: Practical coding for everyone

The test cases were weak ; the following solution gets 100 points :

http://www.codechef.com/viewsolution/7474964

All I did was scale all the elements by 25.

3 Likes

Got AC with big integer calculation without any fast multiplication optimization. The only trick I used is when you divide big integer on another big integer the only precision you need is first 6 digits after decimal point. So it is enough to divide up to 9th digit and the stop dividing.

1 Like

This problem really pissed me off. I was very confident of my solution but I kept getting WA’s. I still don’t know the reason though. My maths is the same as author’s but my answer may be more precise because I am never rounding off (PYTH). I opened up a discussion for this. It will be helpful if someone provides any guidance.

I don’t understand why the author suggests a “fast multiplication method like Karatsuba or FFT” for multiplying bignums. All of the probabilities can be expressed as scalars from 0 <= n <= 1000000, so all you ever need to do is multiply by scalars which takes O(s) time where s is the size of the bignum. This is even faster than Karatsuba and FFT because we’re not multiplying bignums by bignums. Here’s my solution.

In this solution, I simply find the product of all of the probabilities by having one bignum called curProduct and repeatedly taking inputs as scalars (long longs) and then multiplying them into curProduct. Then, in the end, I take the first one and multiply it by 1000000 into sereja and add them all up into sum. I then use binary search to divide sereja by sum and output the resulting number with a decimal point. No Karatsuba or FFT necessary!

@amaneureka Nice idea, but the following test case should not work:

2 10000

0.0001 0.0001 … (5000 times) 0.9999 0.9999 0.9999 … (5000 times)

0.9999 0.9999 0.9999 … (5000 times) 0.0001 0.0001 … (5000 times)

@spagiarri Here :slight_smile:alt text

PS: After watching your comment (at 04:00AM) from mobile, Just to prove my code I booted laptop again :stuck_out_tongue:

I can give you brief explanation that why it worked, but its 4AM and I’m very tired so, sorry :slight_smile:

Why dies my solution passes the subtask 2 but now 1? In JAVA
Link : link text

@amaneureka: can you explain your logic?

1 Like

Please explain your solution

…I HAD TO USE MY OWN bignum LIBRARY IN C AND YOU JUST WALTZ IN AND SCALE THE ELEMENTS BY 25…(so depressed)

1 Like

How did your solution pass? It went over the time limit of 3 seconds!

Your solution is similar to my solution because we both multiplied by scalars instead of using a bignum multiplication algorithm. (I saw your solution here.)

Time limit for java is not 3 seconds. It is for C/C++, I guess. JAVA is slow.

Wow! this is a really good solution! He has just played around with the formula and calculated Ai / A1 on the fly without actually calculating the whole Ai first. Ai is the product of numbers in the ith row (probability that ith guy wins). The answer initially is A1 / (A1 + A2 + … + An). Divide both sides by A1 and you get 1 / (1 + A2/A1 + A3/A1 + … + An/A1). nice!

4 Likes

oh. nice soln. he nailed it :slight_smile:

Yeah, @rushilpaul explained it very correctly. Thanks :slight_smile:
The variable ‘waah’ takes care of when the probability is zero

+1 for the variable names.

2 Likes

@amaneureka: Sorry, I didn’t mean to not let you sleep because of my comment.
If you have time, could you swap the 3rd and the 4th ‘for’ loop? The idea of my test case was that (0.0001/0.9999)^5000 would be 0 because of the precision and that multiplying back by (0.9999/0.0001)^5000 cannot change that. (For example http://paste.ideaslabs.com/show/CvvvJDHinq returns 0 and 0 in Java).