QOJ.ac

QOJ

Süre Sınırı: 1 s Bellek Sınırı: 2048 MB Toplam puan: 100 Hack'lenebilir ✓

#86. Simple Polygon

İstatistikler

You are given a sequence of $n$ points $P_1, P_2, \dots, P_n$ in the plane. Connect consecutive points by line segments, and connect $P_n$ to $P_1$ to close the sequence.

Determine whether these segments form a simple polygon. In this problem, a simple polygon must satisfy all of the following conditions:

  • All $n$ vertices are distinct.
  • Every pair of adjacent edges intersects at exactly their common endpoint. The first and last edges are also adjacent.
  • No pair of nonadjacent edges has any point in common.

Consecutive edges may continue along the same straight line, but they may not overlap or go back along the same segment. The given sequence may contain repeated points; in particular, a zero-length edge is invalid.

Input

The first line of the input contains an integer $T$ indicating the number of test cases. For each test case:

The first line contains an integer $n$ ($3 \le n \le 10^5$), the number of points.

The following $n$ lines describe the points in order. The $i$-th of these lines contains two integers $x_i$ and $y_i$ ($-10^9 \le x_i, y_i \le 10^9$), the coordinates of $P_i$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

Output

For each test case, output Yes if the given sequence forms a simple polygon, and No otherwise, on a separate line. The output is case-sensitive.

Examples

Input 1

6
3
0 0
4 0
0 3
4
0 0
4 4
0 4
4 0
5
0 0
2 0
4 0
4 3
0 3
5
0 0
3 0
3 3
0 0
0 3
5
0 0
4 0
4 4
2 0
0 4
5
0 0
4 0
2 0
4 3
0 3

Output 1

Yes
No
Yes
No
No
No

The first test case is a triangle.

In the second test case, two nonadjacent edges cross.

In the third test case, the first three points lie on the same straight line. The sequence still forms a simple polygon.

In the fourth test case, the first and fourth points coincide.

In the fifth test case, the fourth point lies in the interior of the first edge.

In the sixth test case, the first two edges overlap.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.