#P3055. [USACO12OPEN] Tied Down G
[USACO12OPEN] Tied Down G
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 ties Bessie to a fence with a long rope. Viewed from above, the fence consists of posts with , arranged along a vertical line, with Bessie’s position located to the right of this vertical line. The rope that ties Bessie is described by a sequence of line segments with , where the polyline starts and ends at Bessie’s position. No fence post lies on any rope segment. However, segments may cross, and multiple segments may overlap at their endpoints.
Here is an example of the scene, viewed from above:

To help Bessie escape, the other cows have stolen a saw. Determine the minimum number of fence posts they must cut and remove so that Bessie can pull free, meaning she can run to the right without the rope catching on any fence post.
All coordinates in the input (fence posts, Bessie, and rope endpoints) lie in the range . All fence posts share the same coordinate, and is larger than this value.
Input Format
- Line 1: Four space-separated integers: , , , .
- Lines : Line contains the space-separated and coordinates of fence post .
- Lines : Each of these lines gives, in order, the space-separated and coordinates of a point along the rope. The first and last points are both Bessie’s location .
Output Format
- Line 1: The minimum number of posts that need to be removed 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) and (2, 1). Bessie is at (6, 1). The rope goes from (6, 1) to (2, 4) to (1, 1), and so on, finally ending at (6, 1). The shape of the rope is the same as in the figure above.
Removing either post 1 or post 2 will allow Bessie to escape.
Translated by ChatGPT 5
京公网安备 11011102002149号