Editorial for SAC '22 Code Challenge 4 Junior P3 - Obligatory Triangle Problem
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
It suffices to output .
Time Complexity:
Subtask 2
For each of the points, determine the angle on the unit circle. Trigonometric functions can determine the angle (e.g., atan2). Then, normalize the angle to degrees depending on the coding language.
Declare idx
to be the index of the point with the closest angle currently to and initially .
Next, find the difference between and the current angle.
The angle difference can be determined by , where returns the absolute value of the parameter and and are angles.
If the difference between and the current angle is smaller than the angle difference between and idx
's angle, set idx
to the current index.
Finally, output idx
.
Time Complexity:
Comments