-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
40 lines (38 loc) · 1 KB
/
1007.cpp
File metadata and controls
40 lines (38 loc) · 1 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
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n;
pii p[22];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
cout.precision(7);
cout << fixed;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
vector<int> mask;
for (int i = 0; i < n / 2; i++) mask.push_back(0);
for (int i = 0; i < n / 2; i++) mask.push_back(1);
ll ans = INF;
do {
ll x = 0, y = 0;
for (int i = 0; i < n; i++) {
auto [_x, _y] = p[i];
if (mask[i]) {
x += _x;
y += _y;
} else {
x -= _x;
y -= _y;
}
}
ans = min(ans, x * x + y * y);
} while (next_permutation(mask.begin(), mask.end()));
cout << sqrt(ans) << "\n";
}
}