-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
31 lines (30 loc) · 703 Bytes
/
1007.cpp
File metadata and controls
31 lines (30 loc) · 703 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
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
cout << fixed << setprecision(7);
int tc;
cin >> tc;
while (tc--){
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
vector<int> arr(n);
fill(arr.begin() + n / 2, arr.end(), 1);
double ans = 1e9;
do{
double x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (arr[i]) x += v[i].first, y += v[i].second;
else x -= v[i].first, y -= v[i].second;
}
ans = min(ans, hypot(x, y));
} while (next_permutation(arr.begin(), arr.end()));
cout << ans << endl;
}
return 0;
}