-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
46 lines (46 loc) · 1.02 KB
/
1007.cpp
File metadata and controls
46 lines (46 loc) · 1.02 KB
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
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> dot(20);
bool isSelected[20];
int n;
double ans;
double getMinimum() {
double sumx = 0;
double sumy = 0;
for(int i = 0; i < n; i++) {
if(isSelected[i]) {
sumx += dot[i].first;
sumy += dot[i].second;
} else {
sumx -= dot[i].first;
sumy -= dot[i].second;
}
}
return sqrt(sumx*sumx + sumy*sumy);
}
void selectDot(int depth, int start) {
if(depth == n / 2) {
ans = min(getMinimum(), ans);
return;
}
for(int i = start; i < n; i++) {
if(isSelected[i]) continue;
isSelected[i] = 1;
selectDot(depth + 1, i + 1);
isSelected[i] = 0;
}
}
int main() {
int tc; cin >> tc;
while(tc--) {
ans = 123456789.0;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
dot[i] = {a, b};
}
selectDot(0, 0);
printf("%0.8f\n", ans);
}
}