Can anyone help me solving this problem. I used the following formula
ans = sum of ( pi*|xi|) for all i / sum of pi for all i where xi is positive.
I suppose this formula is correct . If it is then is there any special input
that can make this ans wrong.
thanks in advance.
10777 - God! Save me
Moderator: Board moderators
10777 - God! Save me
hey why doing this
-
- Experienced poster
- Posts: 151
- Joined: Tue Nov 16, 2004 7:23 pm
- Location: Norway
- Contact:
Your approach is the same as in my AC code, so you should get accepted also. Except you didn't mention that you should print "God! Save me" (without quotes) if all xi are negative, make sure you do that
.
Actually, there are potential floating point problems. I rearranged my code a bit to closer resemble yours and ran it on 1000 random generated test cases, and got some results that were different by 0.01. Try moving the divisions in your code and see if you get a different result.
The trickiest input I could figure out was this:
output:
The last one is sneaky, and I'm not sure it occurs in the input. The problem description only says that the sum of all pi equals 1...

Actually, there are potential floating point problems. I rearranged my code a bit to closer resemble yours and ran it on 1000 random generated test cases, and got some results that were different by 0.01. Try moving the divisions in your code and see if you get a different result.
The trickiest input I could figure out was this:
Code: Select all
2
3
3 0.0
-3 0.5
-3 0.5
3
2 1.0
3 -1.0
-3 1.0
Code: Select all
Case 1: God! Save me
Case 2: God! Save me
-
- Learning poster
- Posts: 77
- Joined: Fri Dec 17, 2004 11:06 am
- Location: East West University, Dhaka, Bangladesh
- Contact:
Thanks kathmolla. I got accepted by one submission using your formula.
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/
http://groups.yahoo.com/group/acm_solver/