#P3738. [HAOI2014] 穿越封锁线

[HAOI2014] 穿越封锁线

Description

An enemy-occupied area is a closed polygon represented by consecutive vertices P1(x1,y1)P_1(x_1,y_1), P2(x2,y2)P_2(x_2,y_2), \cdots, Pn(xn,yn)P_n(x_n,y_n).

Our scout ZDM-007 needs to cross the blockade line of the enemy-occupied area. For safety, ZDM-007 travels along a path perpendicular to the XX-axis, moving from south to north.

Given the current position of ZDM-007, can you compute the total length of his route that lies inside the enemy-occupied area while he crosses the blockade line?

Input Format

The first line: nn, the number of polygon vertices.

The next nn lines: xi,yix_i, y_i, the coordinates of the polygon vertices (given in counterclockwise order).

The last line: X,YX, Y, the scout’s initial position.

Output Format

Output the total length of the scout’s path that lies inside the enemy-occupied area while crossing the blockade line. Print only the integer part.

7 
0 1 
2 0
4 1
2 2 
4 3 
2 4 
0 3 
3 -1
2
4
10 100
10 0
100 0
100 100
100 -80
0

Hint

Constraints

$3\le n\le 50, 0\le x_i, y_i \le 1000, 0\le X \le 1000, -100\le Y < 0$.

Translated by ChatGPT 5