Bordering on Madness
Time limit1sMemory limit128 MB
For each of several offsets, compute the total length and the newly painted area of the rectilinear polygon offset outward by a fixed distance.
- Level
Medium7 of 10
- Topics
- Geometry, Implementation, Sorting, Simulation
- Solved
- No attempts yet
Problem
A rectilinear figure is a polygon whose sides all meet at interior angles of 90° or 270° and that contains no holes. A design studio decorates such a figure by drawing one or more rectilinear borders around it. Each border is drawn at a fixed distance outside the previous border — or outside the original figure, for the first border — in the same right-angle style: every straight run of the outline is pushed outward by and the corners stay square. The new region enclosed between a border and the previous outline is painted its own color.
A single border is made of one or more closed rectilinear curves. Where the figure has a narrow concavity, the parts of the border advancing along its two facing walls can meet and seal across the mouth of the concavity; the portion of the border trapped inside then becomes a closed curve of its own, disconnected from the rest of the border. So one border may consist of several separate closed curves. The figures are guaranteed to be chosen so that no border ever has two horizontal sections (or two vertical sections) that touch, even at a single point.
For each figure, report — for every border, from the one nearest the figure outward — two values: the length of that border, which is the combined length of all of its closed curves, and the additional area it contributes, which is the area enclosed by that border minus the area enclosed by the previous border (or the figure, for the first border). A pocket that a border seals off counts as a hole in the area that border encloses, so it is not part of the painted region.
Input
The first line contains a single integer , the number of test cases.
Each test case begins with a line containing three positive integers , , and : the number of vertices of the figure (; a rectilinear polygon has as many vertices as sides), the number of borders to draw (), and the distance between consecutive borders.
The next coordinate pairs give the vertices of the figure, each as two positive integers and . The vertices are listed in clockwise order, starting with the vertex that has the largest coordinate and, among those, the smallest coordinate. The coordinate pairs may be split across several lines.
Output
For each test case, print three lines:
Case k:, wherekis the test case number counting from .- Two spaces followed by
Perimeters:and then the border lengths. - Two spaces followed by
Areas:and then the additional areas.
In both lists the values appear in order from the border nearest the figure outward, separated by single spaces. Print one blank line between consecutive test cases (but not after the last one).