Square of Triangles

시간 제한5초메모리 제한2048 MB

요약
네 삼각형의 변 길이의 제곱이 주어질 때, 겹침이나 빈틈 없이 정사각형으로 배치할 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
기하, 수학, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

You are given the squares of the lengths of the sides of four triangles. Determine if it is possible to arrange them (via translation, rotation, and reflection) into a square. No triangles may overlap, and there should be no gaps or holes.

Figure L.1: A solution to the third test case in the sample input.

입력

The first line of input contains a single integer tt (1≤t≤201 \leq t \leq 20), which is the number of test cases.

Each of the next 4⋅t4 \cdot t lines describes tt test cases, consisting of four triangles each, one triangle per line. Each triangle consists of three integers aa, bb and cc (1≤a,b,c≤1071 \leq a,b,c \leq 10^7). Each of the integers is equal to the square of the length of a side of a triangle. For example, if the three sides of a triangle have lengths 33, 44 and 55, then the input would be 9 16 25. The integers will not necessarily be perfect squares. It is guaranteed that the given triples each represent a triangle of positive area.

출력

Output tt lines. For each test case in order, output a single line with a single integer, which is 11 if the four triangles of the test case can be arranged into a square, and 00 otherwise.

예제1

  1. 예제 1

    입력
    3
    1 1 2
    2 1 1
    2 1 1
    1 2 1
    1 1 1
    1 1 1
    1 1 1
    1 1 1
    5 125 130
    125 20 145
    45 130 145
    145 145 80
    
    예상 출력
    1
    0
    1