Hello everyone,
Probably many of you would have taken part in the Code-Chef Snackdown Qualifier..and would have came across this question.
Well my problem is that I am not able to understand that in which case my code is going wrong... I have taken a look at the Editorial published and I think the pseudocode given there is exactly the same I have implemented. I even asked this same doubt there but have not got any convincing response..so thought to ask here.
Question Link: link 1
Editorial Link: link 2
My Code Link: link 3
My Logic:
First of all I made sure that points are in sorted order..
i.e. Given a horizontal line and if(x11 > x12) then swap(x11,x12)..likewise
1) If both lines are horizontal or vertical, I am just checking that if any one point of a line lies between other two points of other line.
Suppose case is: If both lines are horizontal then:
if((x11>=x21 && x11<=x22) || (x12>=x21 && x12<=x22) || (x21>=x11 && x21<=x12) || (x22>=x11 && x22<=x12)) then true;
else false;
2) If one horizontal and one vertical, I am just checking the four end-points (corners)
Suppose case is: If first line is vertical and other one horizontal then:
if((x21==x11 && y21==y11) || (x21==x12 && y21==y12) || (x22==x11 && y22==y11) || (x22==x12 && y22==y12)) then true;
else false;
I have tried a lot, but still was not able to get the mistake so It would be a great help If someone can please point out a case which I am missing..!
Thank you..!