TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Given a set of rectangles in the plane, determine if it is possible to choose one diagonal from each rectangle such that none of the selected diagonals intersect. Two diagonals intersect if they share at least one point. Note that the rectangles themselves are free to intersect.

Input Format

Input consists of several test cases. Each test case begins with an integer n (1<=n<=1000), representing the number of rectangles. This is followed by n lines each describing a rectangle using 8 integer numbers x1, y1, x2, y2, x3, y3, x4, y4, where each (xi, yi) is a vertex. All coordinate values are between -109 and 109. The input is terminated by a line containing "0" which should not be processed.

Output Format

For each test case, output a line containing either "YES" if the selection is possible or "NO" if not.

Sample Input 1

4
0 1 1 1 1 0 0 0
1 1 2 1 2 0 1 0
2 3 5 3 5 0 2 0
2 3 3 3 3 2 2 2

7
0 10 10 10 10 0 0 0
10 10 20 10 20 0 10 0
20 30 50 30 50 0 20 0
20 30 30 30 30 20 20 20
30 10 40 10 40 0 30 0 
5 0 30 0 30 -10 5 -10
0 0 5 0 5 -10 0 -10

0

Sample Output 1

YES
NO

Hints

Problem Source

Migrated from old NTUJ.

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200