This page is still under construction.

Parts of this page are still being built. What you see may change.

Triangles and Quadrangle

Time limit1sMemory limit128 MB

Summary
Given two triangles and a quadrangle, decide whether the triangles can be joined along a full edge, without overlap, to form the quadrangle up to translation, rotation, and reflection.
Level

Hard8 of 10

Topics
Geometry, Implementation, Sorting, Brute force
Solved
No attempts yet

Problem

Little Yuan is two years old and she is learning about triangles and quadrangles. She is such a smart girl that she soon realizes two triangles that do not overlap each other can be joined to form a quadrangle. She picks up a lot of triangles and uses them to form quadrangles. Unfortunately, she is not good at this kind of jigsaw game yet and sometimes makes mistakes.

As her brother, you are curious whether she has made a mistake when forming a quadrangle from two triangles. Write a program to determine it.

In this problem a quadrangle is defined as a simple polygon with four vertices. You may also assume that every triangle and quadrangle has a positive area.

Two figures are considered the same if and only if one can be made to overlap the other completely by translation, rotation, and flipping (reflection).

Input

The input contains multiple test cases. The first line contains a single integer TT, the number of test cases. (T≤500T \le 500)

Each test case consists of 10 lines.

  • The first 3×2=63 \times 2 = 6 lines describe the two triangles. Each line contains two integers, the coordinates of one point; the first 3 lines are the first triangle and the next 3 lines are the second triangle.
  • The next 4 lines describe the quadrangle, given in clockwise or counter-clockwise order.

All coordinates are less than 1500015000 in absolute value.

Output

For each test case, print one line. For the ii-th test case, print the prefix Case #i: followed by Yes if the two given triangles can be joined without overlapping to form the given quadrangle, or No otherwise. For example, if the answer to the first test case is possible, print Case #1: Yes.

Examples2

  1. Example 1

    Input
    2
    0 0
    0 1
    1 0
    0 0
    0 1
    1 0
    -1 0
    0 0
    1 0
    0 1
    0 0
    -1 1
    1 0
    0 0
    0 1
    1 0
    -1 0
    0 0
    1 0
    0 1
    
    Expected output
    Case #1: Yes
    Case #2: No
    
  2. Example 2

    Input
    1
    0 0
    2 0
    0 2
    0 0
    2 0
    0 2
    0 0
    2 0
    2 2
    0 2
    
    Expected output
    Case #1: Yes