#P17383. [PacNW 2025] Fractal Painting

[PacNW 2025] Fractal Painting

Problem Description

A fractal painting consists of infinitely many line segments. The first segment, called A, connects (0,0)(0,0) to (x0,y0)(x_0,y_0). Segments B and C connect (x0,y0)(x_0,y_0) to (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2), respectively.

The rest of the painting is defined recursively. From (x1,y1)(x_1,y_1), draw segments D and E so that the three-segment figure B-D-E is similar to A-B-C. Here, similar means that one figure can be matched point-for-point to the other by translation, rotation, and scaling. Likewise, draw segments F and G from (x2,y2)(x_2,y_2) so that C-F-G is similar to A-B-C. Continue this process forever.

Determine whether some rectangle of finite size can contain the entire fractal painting.

Input Format

The first line contains an integer TT (1T1041\le T\le10^4), the number of test cases.

Each test case contains six integers x0,y0,x1,y1,x2,y2x_0,y_0,x_1,y_1,x_2,y_2. Every coordinate is between 104-10^4 and 10410^4, inclusive. The points (0,0)(0,0), (x0,y0)(x_0,y_0), (x1,y1)(x_1,y_1), and (x2,y2)(x_2,y_2) are all distinct.

Output Format

For each test case, output YES if the entire painting fits inside some rectangle of finite size. Otherwise, output NO.

3
1 3 -1 3 3 4
1 1 67 0 0 67
67 67 1 0 0 1
YES
NO
YES