#P8608. Sunlit Farm Area Calculation

    ID: 21774 Type: Default 1000ms 256MiB

Sunlit Farm Area Calculation

Sunlit Farm Area Calculation

Planet X is unique in that its rotation speed equals its revolution speed, so sunlight always arrives at a fixed angle. To boost interstellar tourism, Planet X rents out floating disk‐shaped colored clouds to tourists from country Y for sunbathing. However, these clouds block some sunlight, preventing the crops below from growing.

You are given a rectangular farm and several non‐overlapping clouds (each cloud lies entirely within the farm). Each cloud is in the shape of a circle. When a cloud is present, it blocks the sunlight on the part of the farm it covers. Your task is to calculate the total area of the farm that receives sunlight and is thus suitable for growing crops.

Mathematically, if the total area of the farm is \(L \times W\) and each cloud with radius \(r\) blocks an area of \(\pi r^2\), then the area that receives sunlight is:

[ \text{Sunlit Area} = L \times W - \sum_{i=1}^{n} \pi r_i^2 ]

A tolerance of 10-4 in the answer is acceptable.

inputFormat

The input consists of the following:

  • The first line contains two floating-point numbers \(L\) and \(W\), representing the length and width of the rectangular farm.
  • The second line contains an integer \(n\), the number of clouds.
  • Each of the following \(n\) lines contains three floating-point numbers \(x\), \(y\), and \(r\) that denote the center coordinates and radius of a cloud. It is guaranteed that every cloud lies entirely within the farm and that no two clouds overlap.

outputFormat

Output a single floating-point number which is the area of the farm that receives sunlight (i.e. not covered by any cloud). The answer is accepted if it is within 10-4 of the correct answer.

sample

10 5
0
50.0000