#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, V=100%V = 100\%). The coordinates of any point on the wheel are a pair of nonnegative real numbers (α,r%)(\alpha^\circ, r\%) (0α<360,0r1000 \leq \alpha < 360, 0 \leq r \leq 100), meaning a color with hue α\alpha^\circ and saturation r%r\%. Another interpretation is that α\alpha^\circ is the angle swept clockwise from the ray connecting the center of the circle to the pure red point to the given point, and r100\frac{r}{100} is the distance from that point to the center of the unit circle.

0

Specifically, the conversion from these coordinates (α,r%)(\alpha^\circ, r\%) to RGB values (R,G,B)(R, G, B) is as follows:

1

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 (α1,r1%)(α2,r2%)(\alpha_1^\circ, r_1\%)-(\alpha_2^\circ, r_2\%) 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 (R,G,B)(R, G, B) is defined as L=0.30R+0.59G+0.11BL = 0.30R + 0.59G + 0.11B. The figure below shows a side-by-side comparison between the colorful color wheel and a grayscale wheel representing brightness.

2

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 TT — the number of test cases. Then follow TT test cases with no blank lines between them.

Line 1: Four space-separated integers α1\alpha_1, r1r_1, α2\alpha_2, r2r_2.

Output Format

Output to standard output.

For each test case, output one line containing a decimal in the range [0,1][0, 1] — the maximum brightness among all colors on the line segment (α1,r1%)(α2,r2%)(\alpha_1^\circ, r_1\%)-(\alpha_2^\circ, r_2\%), rounded to exactly four decimal places. It is guaranteed that if the reference answer is AA, then any real number in the range [A105,A+105][A - 10^{-5}, A + 10^{-5}] 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 (30,30%)(30^\circ, 30\%) has RGB values (1.00,0.85,0.70)(1.00, 0.85, 0.70), with brightness $0.30 \times 1.00 + 0.59 \times 0.85 + 0.11 \times 0.70 = 0.8785$.

The point (120,60%)(120^\circ, 60\%) has RGB values (0.40,1.00,0.40)(0.40, 1.00, 0.40), with brightness $0.30 \times 0.40 + 0.59 \times 1.00 + 0.11 \times 0.40 = 0.7540$.

The point (270,100%)(270^\circ, 100\%) has RGB values (0.50,0.00,1.00)(0.50, 0.00, 1.00), with brightness $0.30 \times 0.50 + 0.59 \times 0.00 + 0.11 \times 1.00 = 0.2600$.

6

"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