8622: Monotone Chain

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

In computational geometry, polygon triangulation is the decomposition of a polygonal area into a set of triangles. Over time, a number of algorithms have been proposed to triangulate a polygon. One of the special cases is the triangulation of the monotone polygon. It is proved that a monotone polygon can be triangulated in linear time.

A polygon PPP is called monotone with respect to a straight line LLL, if every line orthogonal to LLL intersects the boundary of PPP at most twice. For many practical purposes, this definition may be extended to allow cases when some edges of PPP are orthogonal to LLL.

A monotone polygon can be split into two monotone polygonal chains. A polygonal chain is a connected series of line segments, which can be specified by a sequence of points {A1,A2,…,An}\{A_1,A_2,\dots,A_n\}{A1,A2,,An}. Similarly, a polygonal chain CCC is called monotone with respect to a straight line LLL, if every line orthogonal to LLL intersects CCC at most once, or some line segments of CCC are orthogonal to LLL.

In this problem, we denote a directed line La,bL_{\mathbf{a,b}}La,b by a point a\mathbf{a}a and a direction vector b\mathbf{b}b where La,b={a+λb∣λ∈R}L_{\mathbf{a,b}}=\{\mathbf{a}+\lambda\mathbf{b}|\lambda\in\mathbb{R}\}La,b={a+λbλR}. We define a polygonal chain C={A1,A2,…,An}C=\{A_1,A_2,\dots,A_n\}C={A1,A2,,An} to be monotone with respect to a directed line La,bL_{\mathbf{a,b}}La,b if the following condition is satisfied:
  • For any 1≤i<j≤n1 \le i < j \le n1i<jn, (OAi−a)⋅b≤(OAj−a)⋅b(\mathbf{OA_i}-\mathbf{a})\cdot\mathbf{b}\le(\mathbf{OA_j}-\mathbf{a})\cdot\mathbf{b}(OAia)b(OAja)b.
Here, OAi\mathbf{OA_i}OAi means the coordinate of the point AiA_iAi, and "⋅\cdot'' means the dot product of vectors.

Now given the nnn points in a polygonal chain CCC, please determine whether there exists a directed line La,bL_{\mathbf{a,b}}La,b such that CCC is monotone with respect to La,bL_{\mathbf{a,b}}La,b.

输入格式

The first line contains an integer nnn (1≤n≤1051 \le n \le 10^51n105), indicating the number of points in the polygonal chain.
Each of the next nnn lines contains two integers x,yx,yx,y (−105≤x,y≤105-10^5 \le x,y \le 10^5105x,y105), indicating the coordinates of the points in the polygonal chain. Please note that there may be identical points, even two adjacent points.

输出格式

If there exists a directed line La,bL_{\mathbf{a,b}}La,b such that the polygonal chain is monotone with respect to La,bL_{\mathbf{a,b}}La,b, output YES\texttt{YES}YES in the first line. Then output four integers x1,y1,x2,y2x_1,y_1,x_2,y_2x1,y1,x2,y2 (−109≤x1,y1,x2,y2≤109-10^9 \le x_1,y_1,x_2,y_2 \le 10^9109x1,y1,x2,y2109, (x2,y2)≠(0,0)(x_2,y_2)\neq(0,0)(x2,y2)=(0,0)) in the second line, indicating that a=(x1,y1)\mathbf{a}=(x_1,y_1)a=(x1,y1) and b=(x2,y2)\mathbf{b}=(x_2,y_2)b=(x2,y2). If there are multiple answers, output any.
Otherwise, output NO\texttt{NO}NO in a single line.

输入样例 复制

4
0 1
2 0
0 3
4 3

输出样例 复制

YES
0 -3 1 1

数据范围与提示

A possible solution for the first sample:

分类标签