include iostream include vector include algorithm include cmath using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int n;
double eps = 1e-9;
struct Circle
{
int x;
int y;
int r;
};
vector<Circle> v(50);
vector<pair<double, bool> > q;
double F(double x)
{
q.clear();
pair<double, bool> temp;
for (int i = 0; i < n; i++)
{
if (fabs(x - v[i].x) < v[i].r)
{
temp.first = -sqrt(v[i].r*v[i].r - (v[i].x - x)*(v[i].x - x)) + v[i].y;
temp.second = true;
q.push_back(temp);
temp.first = sqrt(v[i].r*v[i].r - (v[i].x - x)*(v[i].x - x)) + v[i].y;
temp.second = false;
q.push_back(temp);
}
}
sort(v.begin(), v.end());
int rang = 0;
double l, s = 0;
for (int i = 0; i < q.size(); i++)
{
if (q[i].second)
{
if (rang == 0)
l = q[i].first;
rang++;
}
else rang--;
if (i != 0 && rang == 0)
{
s += q[i].first - l;
}
}
return s;
}
double S(double a, double b)
{
return (F(a) + F(b) + 4 * F((a + b) / 2))*(b - a) / 6;
}
double Square(double a, double b)
{
double mid = (a + b) / 2;
if (fabs(S(a, b) - (S(a, mid) + S(mid, b))) < eps)
return S(a, b);
else
return (S(a, mid) + S(mid, b));
}
int main()
{
cin >> n;
Circle temp;
double l, r;
cin >> v[0].x >> v[0].y >> v[0].r;
l = v[0].x - v[0].r;
r = v[0].x + v[0].r;
for (int i = 1; i < n; i++)
{
cin >> v[i].x >> v[i].y >> v[i].r;
if (v[i].x - v[i].r < l)
l = v[i].x - v[i].r;
if (v[i].x + v[i].r > r)
r = v[i].x + v[i].r;
}
cout << Square(l, r) << endl;
return 0;
}