Official

D - Opposite Editorial by en_translator


Let \(q\) be the midpoint of \(p_0\) and \(p_{\frac{N}{2}}\), then \(p_0, p_1, p_2, \dots, p_{N - 1}\) are all on a single circle centered at \(q\).

Also, \(p_0qp_1 = \frac{360^\circ}{N} = \frac{2 \pi}{N}\). (This is because \(p_0, p_1, p_2, \dots, p_{N - 1}\) are equally placed on the circle)

Therefore, the coordinates of \(p_1\) can be found in the following way:

  • Find the coordinates of \(q\)
  • Find the “azimuth” of \(p_0\) from \(q\) (This can be found with the atan2 function in C++ or math.atan2 function in Python)
  • Tilt the azimuth counterclockwise by \( \frac{2 \pi}{N}\) to find the “azimuth” of \(p_1\) from \(q\)
  • Find the \(\mathrm{x}\) and \(\mathrm{y}\) coordinates of \(p_1\) (One can find \(x\) and \(y\) by applying \(\sin\) and \(\cos\) to the “azimuth”)

What is atan2 function?

Both atan2 function in C++ and math.atan2 function in Python are basically the same
It receives \(x\) and \(y\) as the arguments (note that it accepts in the order of \(y, x\)), and returns the “direction” in which the vector \((x, y)\) points
The direction is returned in radians, measured from the direction in the right (the positive direction of \(\mathrm{x}\) axis) as \(0\), with the counterclockwise rotation are regarded as positive
For instance, \(\mathrm{atan2}(0, 3) = 0\). (Because \(x = 3, y = 0\), so it points in the right)
Also, \(\mathrm{atan2}(2, 0) = \frac{\pi}{2}\). (Because \(x = 0, y = 2\) points upwards, which is rotated counterclockwise by \(\frac{\pi}{2}\) from the right)
Note that the angle rounds back after \(2\pi\) rotation, so the returned value is constrained to \((-\pi, \pi]\). You don’t really have to care about the fact (because the \(\sin\) and \(\cos\) function, used for restoring \(\mathrm{x}\) and \(\mathrm{y}\) coordinates, have periods of \(2\pi\), and the range of argument is not constrained)

posted:
last update: