#P4371. Maximum Brightness on a Color Disk Line Segment
Maximum Brightness on a Color Disk Line Segment
Maximum Brightness on a Color Disk Line Segment
In the magical world, the leader must choose a representative color for his magic. The color disk is based on the HSV color space with a fixed maximum value \(V=100\%\). Each color on the disk is represented by a pair \((\alpha^\circ, r\%)\), where \(0 \leq \alpha < 360\) (the hue in degrees) and \(0 \leq r \leq 100\) (the saturation in percent, meaning the distance from the center of the unit circle).
The conversion from \((\alpha^\circ, r\%)\) to RGB \((R, G, B)\) is performed as follows. Let \(S = \frac{r}{100}\) and \(V=1\). Compute the auxiliary value \(C = S\) and \(m = 1 - S\). Then, based on the hue \(H = \alpha\), define:
- if \(0 \le H < 60\): \(R' = C,\; G' = C\cdot\frac{H}{60},\; B' = 0\);
- if \(60 \le H < 120\): \(R' = C\cdot\frac{120-H}{60},\; G' = C,\; B' = 0\);
- if \(120 \le H < 180\): \(R' = 0,\; G' = C,\; B' = C\cdot\frac{H-120}{60}\);
- if \(180 \le H < 240\): \(R' = 0,\; G' = C\cdot\frac{240-H}{60},\; B' = C\);
- if \(240 \le H < 300\): \(R' = C\cdot\frac{H-240}{60},\; G' = 0,\; B' = C\);
- if \(300 \le H < 360\): \(R' = C,\; G' = 0,\; B' = C\cdot\frac{360-H}{60}\).
Finally, set \(R = (R'+m)\times 255\), \(G = (G'+m)\times 255\), \(B = (B'+m)\times 255\). The brightness \(L\) is defined as:
[ L = 0.30,R + 0.59,G + 0.11,B. ]
The input provides a line segment on the disk specified by its two endpoints \((\alpha_1^\circ, r_1\%)\) and \((\alpha_2^\circ, r_2\%)\). Any color on the segment (obtained by linear interpolation in the disk coordinate plane) is available. As the leader wants the brightest color, compute the maximum brightness among all colors on that segment.
Note: In the interpolation, for any parameter \(t\) in \([0,1]\), the color is given by
[ \alpha(t) = \alpha_1 + t, (\alpha_2-\alpha_1), \quad r(t) = r_1 + t,(r_2-r_1). ]
You may assume all formulas are exact and should be implemented with \(\LaTeX\) formatted formulas as above.
inputFormat
The input consists of a single line containing four real numbers:
α1 r1 α2 r2
where \(0 \leq \alpha_1, \alpha_2 < 360\) and \(0 \leq r_1, r_2 \leq 100\).
outputFormat
Output the maximum brightness value achievable on the given line segment. The answer will be accepted if it is correct within a reasonable error tolerance.
sample
0 100 0 100
76.5