Repeatedly getting wrong answer.
Can anyone help me ???
Check this test case: n=3
0 0
0 100
0 -100
Your program is giving 2 but correct answer is 1. This is happening because the compiler treats -inf and inf different (You can check this by printing the slopes). To solve this, check if x2-x1==0 then insert a large value like 5000.0 in the hashmap (The largest value of slope in this problem could be 2000.0). Prior to this, make sure you skip when x2==x1 && y2==y1. Also, rename your class as “Main” before submitting.
Update: I got AC by converting hashmap to long long instead of double. There are precision errors in double. Eg slopes between (-1000,0) and (1000,1) will be same as between (-999,0) and (1000,1) in double. So compute the double value and multiply it by 10^9 and store it as long long in map.
you can also use long double to avoid precision errors
Brother, use SPOJ toolkit : http://www.spojtoolkit.com to find in which test case your code fails to deliver expected output. My implementation: Using mapping : http://ideone.com/eOk2K6 & without mapping : http://ideone.com/R0MILm
yes that works too. thanks
@michelangelo Your tips worked. Finally got accepted. Thanks
And there was no need to check if 2 points are same,it is given that all points will be distinct.