#P4371. [Code+#4] 白金元首与七彩魔法
[Code+#4] 白金元首与七彩魔法
Description
"Make a contract with me and become a magical head of state!"
On this day, the head of state was coaxed by the extraterrestrial creature Kyubey into becoming a magical head of state. However, before practicing magic, the head of state needs to choose a representative color for their magic.
The figure below is a unit-circle color wheel with maximum value (that is, in the HSV color space, ). The coordinates of any point on the wheel are a pair of nonnegative real numbers (), meaning a color with hue and saturation . Another interpretation is that is the angle swept clockwise from the ray connecting the center of the circle to the pure red point to the given point, and is the distance from that point to the center of the unit circle.

Specifically, the conversion from these coordinates to RGB values is as follows:

Please refer to the sample to confirm your understanding and implementation of the formula.
According to Kyubey, the head of state may choose any color on a given line segment lying on the plane of the color wheel. No need to hesitate—being a bling bling imperial leader, of course they will choose the brightest color!
The brightness of a color is defined as . The figure below shows a side-by-side comparison between the colorful color wheel and a grayscale wheel representing brightness.

You need to write a program to compute the maximum brightness among all colors on the given line segment.
Input Format
Read from standard input.
The first line contains a positive integer — the number of test cases. Then follow test cases with no blank lines between them.
Line 1: Four space-separated integers , , , .
Output Format
Output to standard output.
For each test case, output one line containing a decimal in the range — the maximum brightness among all colors on the line segment , rounded to exactly four decimal places. It is guaranteed that if the reference answer is , then any real number in the range will round to the same value at four decimal places.
6
30 30 30 30
120 60 120 60
270 100 270 100
30 30 120 60
120 60 270 100
270 100 30 30
0.8785
0.7540
0.2600
0.9704
0.9408
0.8785
Hint
Sample explanation:
The point has RGB values , with brightness $0.30 \times 1.00 + 0.59 \times 0.85 + 0.11 \times 0.70 = 0.8785$.
The point has RGB values , with brightness $0.30 \times 0.40 + 0.59 \times 1.00 + 0.11 \times 0.40 = 0.7540$.
The point has RGB values , with brightness $0.30 \times 0.50 + 0.59 \times 0.00 + 0.11 \times 1.00 = 0.2600$.

"Ich glaube, ich habe mich klar genug ausgedrückt!"
This statement has nothing to do with historical facts.
Credit: https://www.luogu.org/discuss/show/38908
Translated by ChatGPT 5
京公网安备 11011102002149号