Relay Signal
Time limit2sMemory limit512 MB
Count boats reachable within one relay hop from boat 1, where visibility means the connecting segment never enters the convex island interior; every coordinate is a lattice point.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Binary search, Two pointers
- Solved
- No attempts yet
Problem
People live on an island. Most of them fish for a living, so households on the island own a fishing boat. In the afternoon, when everyone heads out to work, all boats leave the island and float on the sea, and each boat can be drawn as a single point on the coordinate plane. The island is a convex polygon with vertices. Every boat and every vertex of the island sits on a lattice point. The picture below is one example of an island and its boats.

(The orange convex polygon in the middle is the island, and the numbered blue points are the fishing boats.)
Every boat carries a radio, and two boats exchange messages when nothing blocks the way between them. To be exact, two boats exchange messages when the segment joining them does not meet the interior of the island. A segment that only touches a vertex or an edge of the convex polygon does not count as meeting the interior.
When boat runs into trouble, it sends a rescue signal to every boat its signal reaches. Each boat that receives the rescue signal then sends a relay signal to every boat its own signal reaches, telling them that boat is in trouble. A boat that receives a relay signal does not pass the signal on.
You know the vertices of the island and the positions of the boats numbered to . Boat is in trouble. Count the boats that receive at least one of the rescue signal sent by boat and the relay signals sent by the boats that received it. Boat is not counted.
Input
The first line contains the number of boats ().
Each of the next lines describes one boat. The -th of these lines contains the coordinate and the coordinate of boat , separated by a space.
The next line contains the number of vertices of the island ().
Each of the next lines describes one vertex. The -th of these lines contains the coordinate and the coordinate of the -th vertex of the island, separated by a space.
The island is a convex polygon and its vertices are given in counter-clockwise order. Two adjacent edges never have the same slope.
Every coordinate is an integer between and .
All boats have distinct coordinates, and no boat lies inside the island or on its boundary.
Output
Print the number of boats that receive the rescue signal or a relay signal when boat is in trouble.