-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1007.cpp
41 lines (39 loc) · 785 Bytes
/
1007.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
/* reference: http://codersbrunch.blogspot.com/2016/06/1007-vector-matching.html */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef pair<int, int> P;
int t, n;
bool b[20];
vector<P> v;
double answer;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
v.resize(n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &v[i].first, &v[i].second);
b[i] = i % 2;
}
answer = 9999999999;
do {
long long x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (b[i]) {
x += v[i].first;
y += v[i].second;
}
else {
x -= v[i].first;
y -= v[i].second;
}
}
answer = min(answer, sqrt(x*x + y*y));
} while (next_permutation(b, b + n));
printf("%lf\n", answer);
}
return 0;
}