#P7027. [NWRRC2017] Intelligence in Perpendicularia

[NWRRC2017] Intelligence in Perpendicularia

题目描述

There are only two directions in Perpendicularia: vertical and horizontal. Perpendicularia government are going to build a new secret service facility. They have some proposed facility plans and want to calculate total secured perimeter for each of them.

The total secured perimeter is calculated as the total length of the facility walls invisible for the perpendicularly-looking outside observer. The figure below shows one of the proposed plans and corresponding secured perimeter.

Write a program that calculates the total secured perimeter for the given plan of the secret service facility.

输入格式

The plan of the secret service facility is specified as a polygon.

The first line of the input contains one integer nn -- the number of vertices of the polygon (4n1000)(4 \le n \le 1000) . Each of the following nn lines contains two integers xix_{i} and yiy_{i} - the coordinates of the i-th vertex (106xi,yi106).(−10^{6} \le x_{i}, y_{i} \le 10^{6}). Vertices are listed in the consecutive order.

All polygon vertices are distinct and none of them lie at the polygon's edge. All polygon edges are either vertical (xi=xi+1 or(x_{i} = x_{i+1} or horizontal (yi=yi+1)(y_{i} = y_{i+1}) and none of them intersect each other.

输出格式

Output a single integer -- the total secured perimeter of the secret service facility.

题目大意

题目描述

给你一个数 n n ,再给你 n n 个点(xi,yi x_i , y_i ),这 n n 个点依次连成一个多边形。(保证多边形的每条边都与坐标轴平行或垂直,点不重合,点不在边上,边无相交)

求有多长的边是安全的?

(一个单位长度的边是安全的当且仅当它向外平移后能与其余边相遇,结合一下图看看)

输入格式

第一行一个数n n ,表示有多少个定点。

接下来 n n 行,行两个数 xi  yi x_i \; y_i 表示每个点的坐标。

输出格式

一个数,表示安全的长度。

10
1 1
6 1
6 4
3 4
3 3
5 3
5 2
2 2
2 3
1 3

6

提示

Time limit: 3 s, Memory limit: 512 MB.