#BS0000379. Tấm thảm bị ố (Stained Carpet)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tấm thảm bị ố (Stained Carpet)
Stained Carpet
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
ACM manufactures carpets in the shape of equilateral triangles. A manufacturing defect has made some carpets susceptible to stains. ACM will replace a stained carpet if it is one of these carpets.
Let , , and be the vertices of the carpet and let be the location of a stain. The point may lie inside the equilateral triangle or on its boundary. The customer reports three distances , , and .

Determine whether an equilateral carpet can have the reported distances. If so, compute its area. Otherwise, report that no suitable carpet exists.
To account for rounding in the reported decimal measurements, this version uses the following rule. First consider the distances exactly as entered. If no carpet exists, one may decrease exactly one largest distance by at most , keeping the other two unchanged. If this makes a carpet possible, use the smallest such decrease to compute its area. If a carpet is still impossible, the result is -1.000.
Input
One line contains three positive decimal numbers , , and , respectively denoting the distances from the stain to vertices , , and . Each number is written in ordinary decimal notation with an integer part and optionally one to six digits after a decimal point; scientific notation is not used.
Output
Print the area of the carpet, rounded to exactly three digits after the decimal point. If the value is exactly halfway between two rounded values, choose the larger one. If no carpet exists under the rule above, print -1.000.
Subtasks
- Subtask 1 (20 points): ; each number has at most six digits after the decimal point; .
- Subtask 2 (30 points): ; each number has at most six digits after the decimal point; at least two distances are equal.
- Subtask 3 (50 points): ; each number has at most six digits after the decimal point.
Example 1
Input
1 1 1.732051
Output
1.732
Explanation
The stain is the midpoint of a side of length . Both distances to its endpoints equal ; the distance to the opposite vertex is the altitude . The third reported distance exceeds that value by approximately , which is within the permitted adjustment. After adjustment, the area of the equilateral triangle of side is . Rounding gives 1.732.
Example 2
Input
1 1 3.0
Output
-1.000
Explanation
Two vertices are one unit from the stain, so the side joining them has length at most . For a point inside or on the boundary of an equilateral triangle of side at most , its distance to any vertex cannot exceed . The third reported distance is , and the permitted adjustment is too small to satisfy this condition. Thus no carpet exists.
Example 3
Input
1.732051 1.732051 1.732051
Output
3.897
Explanation
All three distances are equal, so the stain is the centre of the equilateral triangle. If the circumradius is , the side is . The area is , approximately . Rounding gives 3.897.