Given the list of coordinates in first quadrant, calculate how many right triangles can be formed from them that have one side parallel x-axisand one side parallel y-axis.
I recently took part in a programming competition, in particular INOI (Indian National Olympiad n Informatics), and this was the first of two questions in the article.
In principle, I realized that any 3 points of type (a,y) (x,y) (x,b)form such a triangle, but they can’t do anything better, and in the end I just wrote the naive O (n ^ 3) (and all my friends).
Can anyone suggest a better way?
And please, THIS DOES NOT CONGRATULATE.
source
share