include iostream include algorithm include vector include cmath includ

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;
struct pt
{
double x, y;
pt()
{
x = y = 0;
}
pt(double x_, double y_)
{
x = x_;
y = y_;
}
};
struct cir
{
pt z;
double r;
cir()
{
z = pt();
r = 0;
}
cir(pt z_, double r_)
{
z = z_;
r = r_;
}
};
vector <cir> ar;
int n;
double eps = 1e-8;
struct pare
{
double y;
int t;
pare()
{
}
pare(double y_, int t_)
{
y = y_;
t = t_;
}
bool operator < (const pare& obj) const
{
if (abs(y - obj.y) < eps)
{
return (t == -1 && obj.t == 1);
}
else
{
return y < obj.y;
}
}
};
vector <pare> line;
double f(double x_)
{
line.clear();
for (int i = 0; i < n; ++i)
{
double x = ar[i].z.x, y = ar[i].z.y, r = ar[i].r;
if (fabs(x - x_) < r - eps)
{
double y1 = y + sqrt(r * r - (x - x_) * (x - x_));
double y2 = y - sqrt(r * r - (x - x_) * (x - x_));
line.push_back(pare(y2, 1));
line.push_back(pare(y1, -1));
}
}
sort(line.begin(), line.end());
int lev = 0;
double lasty = 0;
double ans = 0;
for (int i = 0; i < line.size(); ++i)
{
if (lev == 0)
{
if (line[i].t == 1)
{
lasty = line[i].y;
}
}
lev += line[i].t;
if (lev == 0)
{
if (line[i].t == -1)
{
ans += line[i].y - lasty;
}
}
}
return ans;
}
double integral(double a, double b)
{
return (f(a) + f(b) + 4 * f((a + b) / 2)) * (b - a) / 6.0;
}
double simps(double a, double b)
{
double mid = (a + b) / 2;
double s1 = integral(a, b);
double sl = integral(a, mid);
double sr = integral(mid, b);
if (fabs(s1 - sl - sr) > eps)
return simps(a, mid) + simps(mid, b);
else
return s1;
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
cin >> n;
line.reserve(2 * n);
ar.resize(n);
double a = 10005, b = -10005;
for (int i = 0; i < n; ++i)
{
cin >> ar[i].z.x >> ar[i].z.y >> ar[i].r;
a = min(a, ar[i].z.x - ar[i].r);
b = max(b, ar[i].z.x + ar[i].r);
}
printf("%.5lf", simps(a, b));
return 0;
}