luogu#P3055. [USACO12OPEN] Tied Down G

[USACO12OPEN] Tied Down G

Problem Description

As we all know, Bessie the cow likes nothing more than causing mischief on the farm. To keep her from causing too much trouble, Farmer John decides to tie Bessie down to a fence with a long rope. When viewed from above, the fence consists of NN posts (1N101 \le N \le 10) that are arranged along vertical line, with Bessie's position (bx,by)(bx, by) located to the right of this vertical line. The rope FJ uses to tie down Bessie is described by a sequence of MM line segments (3M10,0003 \le M \le 10,000), where the first segment starts at Bessie's position and the last ends at Bessie's position. No fence post lies on any of these line segments. However, line segments may cross, and multiple line segments may overlap at their endpoints.

Here is an example of the scene, viewed from above:

To help Bessie escape, the rest of the cows have stolen a saw from the barn. Please determine the minimum number of fence posts they must cut through and remove in order for Bessie to be able to pull free (meaning she can run away to the right without the rope catching on any of the fence posts).

All (x,y)(x,y) coordinates in the input (fence posts, Bessie, and line segment endpoints) lie in the range 010,0000 \dots 10,000. All fence posts have the same xx coordinate, and bxbx is larger than this value.

Input Format

  • Line 11: Four space-separated integers: NN, MM, bxbx, byby.
  • Lines 21+N2\dots 1+N: Line i+1i+1 contains the space-separated xx and yy coordinates of fence post ii.
  • Lines 2+N2+N+M2+N\dots 2+N+M: Each of these M+1M+1 lines contains, in sequence, the space-separated xx and yy coordinates of a point along the rope. The first and last points are always the same as Bessie's location (bx,by)(bx, by).

Output Format

  • Line 11: The minimum number of posts that need to be removed in order for Bessie to escape by running to the right.
2 10 6 1 
2 3 
2 1 
6 1 
2 4 
1 1 
2 0 
3 1 
1 3 
5 4 
3 0 
0 1 
3 2 
6 1 
 

1 

Hint

There are two posts at (2,3)(2,3) and (2,1)(2,1). Bessie is at (6,1)(6,1). The rope goes from (6,1)(6,1) to (2,4)(2,4) to (1,1)(1,1), and so on, ending finally at (6,1)(6,1). The shape of the rope is the same as in the figure above.

Removing either post 11 or post 22 will allow Bessie to escape.