SyHoMadara's blog

By SyHoMadara, history, 4 years ago, In English

we have 3 points coordinate of 3 corners of specific rectangle fine the other point you can't use array. Input : in first 3 line we have $$$x_i , y_i$$$ of i-th point. Output : print $$$x_4 , y_4$$$.

example :
   input 
        1 2
        3 5
        3 2
   output 
        1 5

    input 
        11 26
        -2 7
        5 5
    output
        4 28
  • Vote: I like it
  • -7
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

In a rectangle, their diagonals intersect at the midpoint

choose 2 points. find midpoint. Reflect the last point about it. This is a parallelogram.

Try all pairs. one of them has to be a rectangle

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

    I know but how can i write a small algorithm to do this

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      This is short enough to code actually, maybe about 5 lines of code atmost?
      There can be a shorter solution, like if we have a case that the sides of rectangle are parallel to the co-ordinates axis. Otherwise, for a generalised case, this is good enough I think.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        its not. read the sample input.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        but how can i find the diagonals if i choose 2 point it may give a parallelogram not a rectangle