Kazun の競プロ記録

競技プログラミングに関する様々な話題を執筆します.

AtCoder Beginner Contest 246 B問題 Get Closer

問題

atcoder.jp

提出解答

atcoder.jp

問題の概要

座標平面上の原点から点  (A,B) に向かって, 距離  1 だけ移動すると, どの点に移動するか.

制約

  •  0 \leq A,B \leq 1000
  •  (A,B) \neq (0,0)

解法

求めるべき答えは,  d:=\sqrt{A^2+B^2} (\neq 0) とすると,  \left(\dfrac{A}{d}, \dfrac{B}{d} \right) である.

なお,  \theta:=\operatorname{Cos}^{-1} \dfrac{A}{d} とすると,  (\cos \theta, \sin \theta) でもある.