Psp_98's blog

By Psp_98, history, 7 years ago, In English

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

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

The case when the two end points are the same

»
7 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

Hi! I don't know what's wrong with your code, but I ran a stress test (I wrote it when I participated in contest) and it found a test on which your program prints wrong answer. Here it is:

1
7 10 7 10
8 10 5 10

You output "no", but correct answer is "yes".

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    That's it. the case when the two end points are the same isn't being handeled, that's why when the two end points of the other snake doesn't overlap with the first it prints no instead of yes

»
7 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Yupp, the case that you both mentioned was the one I was missing..! Did the necessary changes and Got an AC..!

Thank you @Bassel and @budalnik