Pollution Solution
Time limit1sMemory limit128 MB
Compute the area where a half-disk of radius r centered at the origin overlaps a given polygon above the x-axis.
- Level
Medium7 of 10
- Topics
- Geometry
- Solved
- No attempts yet
Problem
Haebin works at the water pollution control center, monitoring pollutants released into rivers, lakes, and the sea. The task is to measure, as an area, how that pollution affects aquatic ecosystems such as coral reefs and spawning grounds.
The model is as follows. The shoreline is the -axis, and the pollution source is at the origin . The pollution spreads inside a semicircle centered at the origin with radius , that is, the half-disk above the shoreline (the region with ). The ecosystem is given as a single simple polygon whose vertices all satisfy .
Compute the area of the region where the pollution half-disk and the ecosystem polygon overlap.
Input
The first line contains two integers and (, ), where is the number of vertices of the ecosystem polygon and is the radius measured from the source.
Each of the next lines contains the coordinates , of one polygon vertex, listed in counterclockwise order (, ).
The polygon's edges neither cross nor touch one another, and no vertex lies on the arc of the semicircle (the boundary at radius ).
Output
Print the area of the part of the ecosystem polygon that lies inside the half-disk (semicircle) of radius centered at the source. Round the area to exactly six decimal places.