Heracles and the Stables of Augeas
Time limit1sMemory limit256 MB
Pick rivers whose water totals at least W so the sum of straight-line digging distances from the stable is smallest.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Geometry
- Solved
- No attempts yet
Problem
Heracles faced twelve labors. The fifth was not as dramatic as slaying a giant serpent: he had to clean the stables of Augeas, home to more than 1000 cattle and untouched for 30 years, in a single day.
Instead of shoveling by hand, he diverted nearby rivers through the stables. You are given several rivers, each described as a polyline with a water supply. Choose which rivers to divert so the stables receive at least units of water while minimizing total digging distance.
For each chosen river, Heracles digs one straight canal from the stable to the closest point on that river. Canals may cross each other or other rivers, and he cannot merge canals to save work.
Input
The first line contains an integer , the number of data sets. Each data set follows.
The first line of a data set has integers and , then floating-point coordinates and of the stables. , , and is the stable location.
Each of the next lines describes one river. It starts with integer (), the number of points, then integer (), the water supplied. The remaining numbers are the coordinates of the river points in order.
Output
For data set , print Data Set x: on its own line, then on the next line print the minimum total digging distance to obtain at least water, rounded to two decimals. If the rivers cannot supply enough water together, print Impossible. Leave a blank line after each data set.