아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Loop of Chocolate

시간 제한2초메모리 제한1024 MB

요약
같은 크기의 구 n개가 하나의 닫힌 고리를 이루며 이웃한 구끼리만 교차할 때, 구들의 합집합 부피를 구한다.
난이도

보통10점 중 5점

유형
기하, 수학, 구현, 구간
정답자
아직 제출이 없습니다

문제

Let’s make sweets of a fancy shape that is a loop of chocolate.

Figure A.1. A loop of chocolate formed by a union of six spheres

The shape of a loop is formed by a union of a number of spheres of the same size, where every sphere intersects with exactly two others.

(a) Union of four spheres(b) Four intersections of the four spheres in (a)
Figure A.2. A loop of chocolate formed by a union of four spheres

Your job is to write a program that, for given the size and the positions of spheres, computes the total volume of the union of the spheres, i.e., the amount of chocolate required for filling the loop formed by the union.

[Hints] Two spheres of the same radius rr intersect each other when the distance between their centers, dd, is less than 2r2r. The volume of the intersection is known to be 23π(r−d/2)2(2r+d/2).\frac{2}{3}\pi (r - d/2)^2(2r+d/2)\text{.}

The volume of the sphere of radius rr is 4πr3/34\pi r^3/3.

입력

The input consists of a single test case of the following format.

\begin{align\*}\&n \\, r \\\ & x\_1 \\, y\_1 \\, z\_1 \\\ & \vdots \\\ & x\_n \\, y\_n \\, z\_n \end{align\*}

nn and rr are integers. nn is the number of spheres (4≤n≤1004 ≤ n ≤ 100). All the spheres has the same radius rr (2≤r≤1002 ≤ r ≤ 100). (x_k,y_k,z_k)(x\_k, y\_k, z\_k) indicates the coordinates of the center of the kk-th sphere (k=1,…,nk = 1, \dots , n). All of x_kx\_k, y_ky\_k, and z_kz\_k are integers between −100-100 and 100100, inclusive.

The kk-th and the k+1k + 1-th spheres intersect each other for 1≤k<n1 ≤ k < n. The 11-th and the nn-th spheres also intersect. No other pairs of spheres intersect.

출력

Output in a line the volume of the union of the spheres. Relative error of the output should be within 10−710^{-7}.

예제5

  1. 예제 1

    입력
    6 9
    20 0 10
    20 10 0
    10 20 0
    0 20 10
    0 10 20
    10 0 20
    
    예상 출력
    17149.528141
    
  2. 예제 2

    입력
    4 12
    10 10 0
    10 -10 0
    -10 -10 0
    -10 10 0
    
    예상 출력
    27813.56696
    
  3. 예제 3

    입력
    6 9
    23 3 13
    20 10 0
    10 20 0
    3 23 13
    0 10 20
    10 0 20
    
    예상 출력
    17470.837758
    
  4. 예제 4

    입력
    4 2
    0 0 0
    3 0 0
    3 3 0
    0 3 0
    
    예상 출력
    122.52211349
    
  5. 예제 5

    입력
    8 70
    100 100 0
    0 100 0
    -100 100 0
    -100 0 0
    -100 -100 0
    0 -100 0
    100 -100 0
    100 0 0
    
    예상 출력
    10220648.1