問題一覧 > 通常問題

No.3344 Common Tangent Line

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差が $10^{-4}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 17
作問者 : 2251799813685248 / テスター : tassei903 jupiter_68 noya2
お気に入りにしたユーザー ProblemId : 12805 / 自分の提出
問題文最終更新日: 2025-11-13 17:50:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 作問ハッカソンコンテスト 003 Day1 (順位表) の他の問題:

Problem Statement

There are $2$ circles $1,2$ on the $xy$-plane, which consists of $2$ orthogonal axes (the $x$-axis and the $y$-axis). These $2$ circles have no intersection points, and neither of them lies inside the other.

Circle $1$ has center $(C_{1x},C_{1y})$ and radius $r_1$, and circle $2$ has center $(C_{2x},C_{2y})$ and radius $r_2$.

Find all $4$ lines that are tangent to both of these $2$ circles simultaneously, apply a specific process to them to obtain $1$ real number, and output that real number.

For the specific process, refer to the output format below.

Note that it can be shown that, under the constraints, exactly $4$ such lines always exist. (See the image in Sample 1.)

You are given $T$ test cases; find the answer for each of them.

Constraints

  • $1 \leq T \leq 2\times 10^{5}$
  • $-100 \leq C_{1x},C_{1y},C_{2x},C_{2y} \leq 100$
  • $(C_{1x},C_{1y}) \neq (C_{2x},C_{2y})$
  • $0 < r_1 \leq r_2 \leq 100$
  • $\sqrt{(C_{2x}-C_{1x})^2+(C_{2y}-C_{1y})^2} > r_1+r_2$
  • All inputs are integers.

Input

$T$
$\text{case}_1$
$\text{case}_2$
$\text{case}_3$
$\vdots$
$\text{case}_T$

Each test case is given in the following format.

$C_{1x} \ \ C_{1y} \ \ r_1$
$C_{2x} \ \ C_{2y} \ \ r_2$

Output

Output the results for all $T$ cases.
For each case, first represent the $4$ lines in the following forms, using a total of $12$ real numbers $a_1,a_2,a_3,a_4,b_1,b_2,b_3,b_4,c_1,c_2,c_3,c_4$.

  • $a_1x+b_1y+c_1=0$
  • $a_2x+b_2y+c_2=0$
  • $a_3x+b_3y+c_3=0$
  • $a_4x+b_4y+c_4=0$

Then, perform the following operation on each of the equations.

When the equation of a line is $ax+by+c=0$, define $M=\text{max}(|a|,|b|,|c|)$. Then divide all coefficients of the equation by $M$. That is, replace $a,b,c$ with $\frac{a}{M}, \frac{b}{M}, \frac{c}{M}$, respectively.

Suppose that the result of performing this operation on each of the $4$ lines is as follows. (The letters representing the coefficients after the operation are marked with '.)
  • $a'_1x+b'_1y+c'_1=0$
  • $a'_2x+b'_2y+c'_2=0$
  • $a'_3x+b'_3y+c'_3=0$
  • $a'_4x+b'_4y+c'_4=0$


Finally, find and output the value $X$ defined by the following expression.

$X=|a'_1+b'_1+c'_1| + |a'_2+b'_2+c'_2| + |a'_3+b'_3+c'_3| + |a'_4+b'_4+c'_4|$

It can be shown that this value is always the same regardless of how the lines are represented and in what order they are arranged.

Output Format
Let $X_i$ denote the value of $X$ for case $i$. Output $X_1$, $X_2$, $X_3$ $\dots$ $X_T$ separated by newlines, for a total of $T$ lines.
$X_1$
$X_2$
$X_3$
$\vdots$
$X_T$
Your output is considered correct if its absolute error from the expected solution is at most $10^{-4}$. It is guaranteed that the absolute error between the expected solution and the true value is at most $10^{-9}$.

Sample

Sample 1
Input
3
1 1 1
4 -2 2
16 -34 14
-76 99 29
0 -16 8
0 16 8
Output
3.0923292192132454
4.8406596632442525
4.0000000000000000


Let us explain the first case of Sample 1.
The $4$ lines from which the answer is derived are represented by the following equations. (The coefficients are written explicitly.)
Converting these according to the specific operation gives the value in the sample output.

  • $1x+0y-2=0$
  • $0x+1y+0=0$
  • $(\text{cos}T) x + (\text{sin}T) y -1 - \text{cos}T - \text{sin}T = 0 \space(T = \frac{\pi}{4} + \text{arcsin}{\frac{1}{3\sqrt{2}}})$
  • $(\text{cos}U) x + (\text{sin}U) y -1 - \text{cos}U - \text{sin}U = 0 \space(U = \frac{5}{4} \pi - \text{arcsin}{\frac{1}{3\sqrt{2}}})$


提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。