#P12535. [XJTUPC 2025] 棱堡

    ID: 12370 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>计算几何2025Special JudgeO2优化凸包高校校赛

[XJTUPC 2025] 棱堡

Description

A bastion is the first type of fortress that relies solely on direct firepower and has no attack blind spots.

A simple non-degenerate polygon is a closed polygonal region\textbf{region} composed of a sequence of nn (n3n\ge 3) vertices, satisfying the following conditions:

  • The vertex sequence connects end to end, forming nn edges, constituting a compact closed set in the plane (including all boundary and interior points);
  • The nn edges only meet at the vertices and do not intersect each other (adjacent edges have no other intersection points outside the common vertex);
  • The nn vertices are distinct, not located inside any non-adjacent edges, and any three consecutive vertices are not collinear.

The bastion can be viewed as a simple non-degenerate polygon composed of nn points and nn edges. For two distinct points PP and QQ on the edges of the polygon, we define that point PP can directly fire at point QQ if and only if the line segment PQPQ intersects the polygon only at points PP and QQ. As shown in the figure below, points AA and BB cannot directly fire at point XX, but point CC can. If there is a point PP on the edge of the polygon such that there is no other point QQ on the edge of the polygon for which point QQ can directly fire at PP, then we call point PP a fire blind spot of the polygon.

We call a simple non-degenerate polygon a bastion if and only if it has at most a finite number of points that are fire blind spots. Given a simple non-degenerate polygon, please determine whether it is a bastion.

Formally, given a simple non-degenerate polygon, please determine whether there are only a finite number of points PP located on the edges of the polygon such that there is no other point QQ on the edges of the polygon for which the line segment PQPQ intersects the polygon only at points PP and QQ.

Input Format

The input contains multiple test cases. The first line of the data contains an integer tt (1t1041 \leq t \leq 10^4) indicating the number of test cases. The following describes each test case.

The first line of each test case contains an integer nn (3n1053 \leq n \leq 10^5), which is the number of edges of the polygon.

The next nn lines each contain two integers xix_i and yiy_i (109xi,yi109-10^9 \leq x_i, y_i \leq 10^9), describing a vertex of the polygon.

The input data guarantees that a simple non-degenerate polygon is formed. The vertices are given in counterclockwise order, that is, after traversing all the vertices in order, it rotates exactly 360360^\circ counterclockwise. Connect edges in sequence according to the input order of the vertices (the ii-th vertex is connected to the (i+1)(i+1)-th vertex, and the nn-th vertex is connected back to the 11-st vertex).

It is guaranteed that the sum of nn for all test cases does not exceed 2×1052 \times 10^5.

Output Format

For each test case, output a single line containing a string. If the polygon is a bastion, output YES\tt{YES}; otherwise, output NO\tt{NO}. The answer is case insensitive.

2
20
7 5
9 5
13 13
5 9
5 7
-5 7
-5 9
-13 13
-9 5
-7 5
-7 -5
-9 -5
-13 -13
-5 -9
-5 -7
5 -7
5 -9
13 -13
9 -5
7 -5
4
1 1
-1 1
-1 -1
1 -1
YES
NO