-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCatchingShadeinFlatland99.cpp
More file actions
39 lines (38 loc) · 958 Bytes
/
CatchingShadeinFlatland99.cpp
File metadata and controls
39 lines (38 loc) · 958 Bytes
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
#include <iostream>
#include <iomanip>
#include <cmath>
#define PI 3.14159265
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == 0)
return 0;
int *x = new int[n];
int *y = new int[n];
int *r = new int[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> r[i];
}
double max = 0.0;
for (double i = 0.0; i <= 360.0; i += 0.25) {
double a = 500 * cos(i*PI / 180);
double b = 500 * sin(i*PI / 180);
double c = 0;//y intercept is zero
double sum = 0.0;
for (int j = 0; j < n; j++) {
double dist = (a*x[j] + b * y[j] ) / sqrt(pow(a, 2) + pow(b, 2));//perpendicular distance from the line to the center of the circle
if (dist < 0)
continue;
dist = x[j] * x[j] + y[j] * y[j] - dist * dist;
if (dist < r[j]*r[j]) {
sum += 2 * sqrt(pow(r[j], 2) - dist);//pythagoras
}
}
if (sum > max)
max = sum;
}
cout << setprecision(3) << fixed << max << endl;
}
return 0;
}