PROBLEM LINK:Author: Kanstantsin Sokal DIFFICULTY:Cakewalk PREREQUISITES:Basic geometry PROBLEM:
QUICK EXPLANATION:
EXPLANATION:
Since all coordinates are integers, we are going to give a solution, which uses only operations over integers in order to avoid any floating point equality checking. This is a common trick, and it’s worth to consider using it while solving this kind of problems. SUBTASK 1
The task is supposed to be pretty straightforward. Let $d^2(A, B)$ be the squared distance between points $A$ and $B$. In other words, this is the squared length of a side of the triangle between points $A$ and $B$. Notice that $d^2(A, B)$ can be easily computed $(A.x  B.x)^2$ + $(A.y  B.y)^2$, because its just a squared Euclidean distance. In order to classify a triangle according to its sides, the only thing we need to do is to compare squared lengths of all its 3 sides. Either none of them are equal or exactly 2 of them are equal, which gives us the answer. Notice that we are using the fact that for two positive integers $C$ and $D$, $C$ and $D$ are equal if and only if $C^2$ and $D^2$ are equal. This let us to avoid floating point operations here. SUBTASK 2
This seems to be slightly harder than the first subtask. You may think of using some sort of trigonometry functions here, but in fact, there is a quite clever and smooth solution based on Pythagorean theorem. Let $a^2, b^2, c^2$ be the squared lengths of sides of a triangle in nondescending order. Then the triangle has exactly one right angle if and only if $a^2 + b^2 = c^2$. Moreover, it has exactly one obtuse angle if and only if $a^2 + b^2 < c^2$. Otherwise, all its angles are acute. Since we know how to compute squared lengths of all the sides, we can easily classify a triangle according to its angles using this method. Notice that all these computations are again done only over integers. AUTHOR'S AND TESTER'S SOLUTIONS:Author's solution can be found here.
This question is marked "community wiki".
asked 31 Jan '16, 03:50

Reading the question and using acos and asin method to compute the angles was a bit harder. Rather simply classifying the triangles based on *Pythagoras theorem* was more clever and an easy task. answered 02 Feb '16, 19:52

nice check for finding if triangle is obtuse. Thanks. answered 28 Feb '16, 21:33
