forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcranes.cpp
84 lines (71 loc) · 1.63 KB
/
cranes.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct crane {
ll x;
ll y;
ll r;
};
bool touch(crane c1, crane c2) {
ld dist = sqrt(pow(c1.x - c2.x, 2) + pow(c1.y - c2.y, 2));
return (dist <= (c1.r + c2.r));
}
ll calc(vector<vector<bool>>& c, vector<crane>& v, ll i) {
vector<ll> use;
ll curr = 0;
while(i > 0) {
if(i % 2 == 1) {
use.push_back(curr);
}
i >>= 1;
curr++;
}
bool works = true;
for(ll i = 0; i < use.size() && works; i++) {
for(ll j = i+1; j < use.size() && works; j++) {
if(i == j) {
continue;
}
if(c[use[i]][use[j]]) {
works = false;
}
}
}
if(works) {
ll total = 0;
for(auto i : use) {
ll here = v[i].r;
total += here*here;
}
return total;
}
return 0;
}
int main() {
ll cases;
cin >> cases;
while(cases--) {
ll n;
cin >> n;
vector<crane> v(n);
for(auto& i : v) {
cin >> i.x >> i.y >> i.r;
}
vector<vector<bool>> collision;
collision.resize(n, vector<bool>(n,false));
for(ll i = 0; i < n; i++) {
for(ll j = 0; j < n; j++) {
if(i==j) {
continue;
}
collision[i][j] = touch(v[i],v[j]);
}
}
ll best = 0;
for(ll i = 1; i < (1<<n); i++) {
best = max(best, calc(collision, v, i));
}
cout << best << endl;
}
}