P2316 [HNOI2005] Fractal
Description



A fractal has a fractional dimension, between $2$ and $3$. A complete fractal picture often has a bounded area and an infinite perimeter. To explore the secrets of fractals, King persistently conducts an unconventional study.
He first studies a simple fractal: In the plane, there is a circle of radius $R_0$ ($R_0 = 10^5$) centered at the origin. It is externally tangent to several circles of radius $R_1$. Each circle of radius $R_1$ is externally tangent to several circles of radius $R_2$, …, and each circle of radius $R_i$ is externally tangent to several circles of radius $R_{i+1}$. Any two circles do not intersect, do not overlap, are not contained one in another, and are not internally tangent. A circle of radius $R_i$ can only be externally tangent to circles of radius $R_{i-1}$ or $R_{i+1}$, and for $i > 0$ it is externally tangent to exactly one circle of radius $R_{i-1}$.
As a foundation, he first studies a finite-layer simple fractal, that is, an $(n + 1)$-layer fractal composed only of circles with radii $R_0$ through $R_n$. Figure 1 shows a $5$-layer simple fractal. Since there are only finitely many layers, the boundary length is finite.
On the boundary, King identifies several pairs of points $(P_i, Q_i)$ related to the properties of the fractal picture. From $P_i$ to $Q_i$, what is the length of the shortest smooth path (see the bold curve in Figure 1).
A smooth path means: at a common tangent point of two circles, when the path turns, its tangent direction remains unchanged. In Figure 2, the two bold paths on the left are smooth, while the bold path on the right is not smooth.
Input Format

The first line contains $3$ integers $n, m, t$. Here $m$ is the number of circles (and the circles are numbered $1$ through $m$), and $t$ is the number of special point pairs.
The second line contains $n$ positive integers $R_1$ through $R_n$.
Each of the next $m$ lines describes a circle. Each line contains $4$ numbers $X_i, Y_i, S_i, F_i$. $(X_i, Y_i)$ is the center of circle $i$. The radius of circle $i$ is $R_{S_i}$. The index of the larger circle tangent to circle $i$ is $F_i$. $X_i$ and $Y_i$ may be real numbers.
Each of the next $t$ lines describes a special pair of points. Each line contains $4$ numbers $P_{i,tW}, P_{i,tA}, Q_{i,tW}, Q_{i,tA}$, which specify the locations of a special pair $(P_i, Q_i)$:
- $P_{i,tW}$ means point $P_i$ lies on circle $P_{i,tW}$, and with the center of this circle as the origin, its argument (angle) is $P_{i,tA}$.
- $Q_{i,tW}$ means point $Q_i$ lies on circle $Q_{i,tW}$, and with the center of this circle as the origin, its argument (angle) is $Q_{i,tA}$.
Output Format

For each special pair, output one line containing one integer, which is the shortest length divided by $\pi$, rounded to the nearest integer.
Explanation/Hint

For $50\%$ of the testdata:
- $m \le 300$.
- $t \le 1000$.
For $100\%$ of the testdata:
- $1 \le n < m \le 3000$.
- $1 \le t \le 10^5$.
- $2 \le R_n < R_{n-1} < \ldots < R_1 < R_0$.
- $R_{i-1} - R_i \ge 2$.
- $R_0 = 10^5$.
- $S_0 = -1$.
- $X_1 = Y_1 = F_1 = S_1 = 0$.
- $-3 \times 10^8 \le X_i, Y_i \le 3 \times 10^8$.
- $0 \le S_i \le n$.
- $1 \le F_i \le m$.
- $F_i \ne i$.
- $S_{F_i} = S_i - 1$.
- $1 \le P_{i,tW}, Q_{i,tW} \le m$.
- $P_{i,tW} \ne Q_{i,tW}$.
- $0 \le P_{i,tA}, Q_{i,tA} < 2\pi$.
- Any two circles are either externally tangent or disjoint.
- All special points are not points of tangency.
- Each circle is externally tangent to at most $10$ circles.
- All real numbers have at most $6$ decimal places.
Translated by ChatGPT 5