Eerie Shadows
Time limit1sMemory limit1024 MB
Given a bridge with symmetric pillar pairs and two lamps at one end, compute the area of the bridge ahead that lies in at least one lamp's shadow.
- Level
Medium7 of 10
- Topics
- Geometry, Intervals, Math, Implementation
- Solved
- No attempts yet
Problem
One night, as you walk home across a bridge, you notice that the shadows from two large lamps at one end of the bridge form an interesting symmetrical pattern on the ground. The two lamps are equally far from the sides of the bridge on both sides.
The bridge has pillars in pairs at irregular sizes and intervals, and every pillar always has an identical pillar on the opposite side. You may assume that the parts of the pillars above ground level are infinitesimally thin and that the bridge is infinitely long.

Figure E.1: A visualisation of the second sample input.
How much of the bridge ahead of you is in the shadow of at least one lamp?
Input
The input consists of:
- One line containing two integers and (, ). is the distance in centimetres from the middle of the bridge to either side, and is the distance from the sides of the bridge to the lamps.
- One line containing one integer (), the number of pillar pairs.
- further lines, each containing two integers and (). They give the distances in centimetres from the end of the bridge to the start and end of one pair of pillars. For all , .
Output
Output the total area in square centimetres that is shadowed by the pillars. The absolute or relative error of your output must be at most .