Repository navigation
Expand file tree
/
Copy path1007.cpp
More file actions
59 lines (55 loc) · 1.44 KB
/
Copy path1007.cpp
File metadata and controls
59 lines (55 loc) · 1.44 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
47
48
49
50
51
52
53
54
55
56
57
58
59
#define ll long long
#include <bits/stdc++.h>
using namespace std;
int N;
vector<pair<ll,ll>> v;
bitset<21> selected;
pair<ll, ll> ans = {1e7, 1e7};
void select(int rest, int idx){
if( rest == 0 ){
// selected가 false 인 것을 종점(to)라고 정의
pair<ll, ll> ret = {0, 0};
for(int i=0; i<N; i++){
if( selected[i] ){
ret.first -= v[i].first;
ret.second -= v[i].second;
}
else{
ret.first += v[i].first;
ret.second += v[i].second;
}
}
if( ret.first * ret.first + ret.second * ret.second <
ans.first * ans.first + ans.second * ans.second ){
ans.first = ret.first;
ans.second = ret.second;
}
return;
}
for(int i=idx; i<N; i++){
if(selected[i])
continue;
selected[i] = true;
select(rest-1, i+1);
selected[i] = false;
}
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T;
cin >> T;
cout.precision(7);
cout << fixed;
while(T--){
cin >> N;
v.resize(N), selected.reset();
ans = {1e7, 1e7};
for(int i=0; i<N; i++){
cin >> v[i].first >> v[i].second;
}
select(N/2, 0);
cout << sqrt( ans.first * ans.first + ans.second * ans.second ) << '\n';
}
return 0;
}