CCO Preparation Test 2 P2 - Forest Area

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 0.6s
Memory limit: 128M

Author:
Problem types

Bruce is inspecting the forest coverage in Trianglesland, where each forest is an isosceles right triangle. To simplify the problem, the map of Trianglesland can be treated as an x-y plane and there are N forests in this plane. For each forest, the two right-angle sides are parallel to the axes, while the hypotenuse is from top left to bottom right, which is illustrated in the following figure.

In Trianglesland, each forest is denoted by three non-negative integers (x,y,d), representing the coordinates of three vertices (x,y), (x+d,y), and (x,y+d). Bruce has obtained the vertex coordinates of each forest. But some forests overlap. Can you write a program to help Bruce calculate the area covered by the forest (the gray regions in the following figure)?

Input Specification

The first line of input will consist of one integer N, the number of forests in Trianglesland.

Each of the next N lines will consist of three integers x, y, d, representing that the vertex coordinates of the forest are (x,y), (x+d,y), and (x,y+d). 0 \le x, y, d \le 10^6.

In 50\% of the test cases, 1 \le N \le 500.

In 100\% of the test cases, 1 \le N \le 10\,000.

Output Specification

Output the total area covered by the forest, rounded to one decimal place.

Sample Input

3
1 1 4
2 0 2
3 2 2

Sample Output

11.0

Comments

There are no comments at the moment.