The Hare and the Hedgehogs
Time limit1sMemory limit128 MB
Hedgehogs of equal speed start at given points and may move freely; find the maximum number of legs they can collectively reach exactly when the hare arrives.
- Level
Medium7 of 10
- Topics
- Geometry, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Germany has a famous fable about a hare and a hedgehog. The hare keeps bragging about how fast he is, so the hare and the hedgehog agree to a race across a field. The instant the race begins the hare sprints off, but when he reaches the far end the hedgehog is already there. He dashes back even faster, yet the hedgehog is waiting there too. He runs back and forth faster and faster, meeting the hedgehog at the opposite end every time, until he finally collapses. Of course the hedgehog won, because the one waiting at the far end was actually his wife. When the story is told to children the moral is usually taken to be either that boasting invites humiliation, or that teamwork is powerful. Unfortunately, the lesson the story really teaches is that it is easy to win if you cheat.
Here we consider a more elaborate race between one hare and several hedgehogs. The hare's course is made of several straight legs, given by a sequence of points in the plane. The race starts at the origin . The hare runs at a constant speed in a straight line to , then in a straight line to , and so on to .
The hedgehogs move at a (possibly different) speed and may walk anywhere they like. Scoring works as follows. At the exact moment the hare reaches (), if at least one hedgehog is standing on , the hedgehogs win that leg; otherwise the hare wins it. If a hedgehog and the hare reach the point at exactly the same time, the hare wins the leg. Compute the largest number of legs the hedgehogs can win as a team.
Input
The first line contains the number of data sets. It is followed by data sets, each of the following form.
The first line of a data set contains two integers , and two floating-point numbers , . Here is the number of legs to be run, is the number of hedgehogs on the field, is the hare's speed, and is the hedgehogs' speed, both in m/s.
This is followed by lines, each giving the coordinates of a point as two floating-point numbers. This is followed by lines, each giving the initial coordinates of hedgehog . Hedgehog always starts at the origin. All coordinates are in meters.
Output
For each data set, first output a line "Data Set x:", where x is its number (starting from 1). On the next line, output the maximum number of legs the hedgehogs can win together. Print one blank line between consecutive data sets.