Tangram
Time limit8sMemory limit512 MB
Given a simple polygon whose edges run horizontally, vertically, or diagonally, decide whether all seven tangram pieces can tile it without overlap.
- Level
Hard8 of 10
- Topics
- Backtracking, Geometry, Implementation
- Solved
- No attempts yet
Problem
Chen, your pretty sister, has been stuck on a tangram puzzle for an hour and came to you for help. The tangram is a puzzle rooted in China. The goal is to form a given shape using all seven pieces. Each piece can be placed anywhere, and rotated and flipped in any way, but pieces cannot overlap.
The seven pieces are:
- Two small right triangles (edge lengths , , and )
- One medium right triangle (edge lengths , , and )
- Two big right triangles (edge lengths , , and )
- One square (side length )
- One parallelogram (side lengths and )
Given the shape of a polygon , determine whether can be made by using all seven pieces. You may assume the following.
- Each edge of is parallel to the -axis, the -axis, the line , or the line .
- is connected and has no hole. is a simple polygon, so its edges do not cross or touch each other.
Input
The first line contains an integer (), the number of vertices of . Each of the next lines gives a vertex of in clockwise order. Each line contains four non-negative integers , , , and , separated by spaces. The vertex is at . No coordinate exceeds 1000.
Output
Print "Yes" on a line if can be made with the seven pieces. Otherwise, print "No".