-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
55 lines (47 loc) · 936 Bytes
/
1007.cpp
File metadata and controls
55 lines (47 loc) · 936 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
vector<int> X;
vector<int> Y;
int N;
double answer = 1e10;
void dfs(int cnt, int positive, int negative, int x, int y)
{
if (cnt == N)
{
double tmp = sqrt(pow(x, 2) + pow(y, 2));
if (answer > tmp)
{
answer = tmp;
}
return;
}
if (positive < N / 2)
{
dfs(cnt + 1, positive + 1, negative, x + X[cnt], y + Y[cnt]);
}
if (negative < N / 2)
{
dfs(cnt + 1, positive, negative + 1, x - X[cnt], y - Y[cnt]);
}
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
answer = 1e10;
scanf("%d", &N);
X.assign(N, 0);
Y.assign(N, 0);
for (int i = 0; i < N; i++)
{
scanf("%d %d", &X[i], &Y[i]);
}
dfs(0, 0, 0, 0, 0);
printf("%.8lf\n", answer);
}
return 0;
}