Sunday, January 23, 2011

Finally "Passed System Test"

With two consecutive disappointments in SRM 492 and SRM 493, finally I code everything well and everything goes fine.
In SRM 492 the 250 problem seemed easy, I developed the logic pretty fast for this problem. Any line would pass through two points, so I fixed two points and calculated maximum number of trees such, that they were co-linear. I coded everything fine, but was missing a very important point. Double precision, I was working with dividing the value, and then comparing them.
If A and B are two double type variables, and they need to be compared for equality, then if we do
if(A == B) , then we may fail, because of floating point precision. Instead we should do if(abs(A-B) <= 1e-9) I failed system test due to this issue, just adding this condition passed system test in practice room.

In SRM 493 the 250 problem, seemed an easy game theory problem, with the concept that, if the first player can win in first chance, then he can win, and if he cant then if the second player can win in first chance then he is the winner. And in other cases there is a draw. I miss interpreted the question, it said reverse their order. There are some black and white stones suppose "OOOXO", where X represent a black stone and O represent a white stone. Reversing the order meant OOOXO --> OXOOO. I interpreted it as OOOXO --> XXXOX. The test cases were such that by writing the code thinking about this logic, it passed all the cases. I got one more wrong answer.

Finally after two failures SRM 494
the 250 seemed easy, I thought of the logic, and implemented the solution, was making some mistakes, fixed those bugs and the submitted. I wanted to get this right, so was coding the solution very patiently. Finally got it accepted, and increased my rating to 1296.

Now I'll practice more and try to get the 500 pointer. That will be my next target. And become top 50 in India.

No comments:

Post a Comment