Блог пользователя Psp_98

Автор Psp_98, история, 7 лет назад, По-английски

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

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

The case when the two end points are the same

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    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 лет назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

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