Shore Erosion
Time limit8sMemory limit512 MB
Given a counterclockwise polygon and erosion distance R, find the total boundary length left after removing points within Manhattan distance R of the coast.
- Level
Hard8 of 10
- Topics
- Geometry, Implementation
- Solved
- No attempts yet
Problem
You are a programmer who works for the local city hall. The town depends heavily on tourism, and a beach on a remote island is especially popular. The coastline of this island is made of sandy beaches, but in recent years coastal erosion has reduced the beach area. Alarmed by this, the tourism office has asked you to simulate how the shape of the beaches will change.
The simulation takes the current shape of the beaches and finds their shape after a certain period. For simplicity, the island's coastline is treated as a polygon, which is not necessarily convex. During the period, the beach is assumed to erode by Manhattan distance from the current coastline and sink into the sea. The Manhattan distance is the sum of the difference in x coordinates and the difference in y coordinates. That is, the Manhattan distance between and is .
Your task is to write a program that computes the length of the coastline after the simulation, starting from the given coastline. If erosion splits the island into two or more pieces, compute the coastline length of each piece and output their sum.
For any two line segments on the coastline that are parallel, their Manhattan distance is never exactly .
Input
The input consists of multiple datasets. Each dataset is given in the following format.
N R
x1 y1
x2 y2
...
xN yN
The first line contains two non-negative integers () and (). They are the number of vertices of the coastline and the distance by which the beach erodes. The next lines each contain the coordinates of one vertex, given as two integers and (). The -th vertex of the coastline is . The vertices of the island are always given in counterclockwise order.
The input ends with a line containing two zeros separated by a space.
Output
For each dataset, output the length of the coastline after erosion. If the island erodes completely and disappears, treat the coastline length as 0.0. The output may have an error of up to 0.01. You may print any number of digits after the decimal point.