Snackdown Same-Snake Problem

Revision en1, by Psp_98, 2017-05-27 00:29:48

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..!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Psp_98 2017-05-27 00:34:00 16 Tiny change: 'sing..!** ' -> 'sing..!** \n\nThank you..!'
en1 English Psp_98 2017-05-27 00:29:48 1689 Initial revision (published)