-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy path2D point meeting.cpp
executable file
·81 lines (71 loc) · 2 KB
/
2D point meeting.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
#define ld long double
int check(ld h,ld k,ld arr_x[],ld arr_y[],int n){
int steps = 0;
for(int j=0;j<n;j++){
ld xx=h-arr_x[j];
ld yy=k-arr_y[j];
if(xx==0 && yy==0){
steps+=0;
}
else if ((xx==0 && yy!=0) || (xx!=0 && yy==0)){
steps+=1;
}
else if(abs(xx)== abs(yy)){
steps+=1;
}
else steps+=2;
}
return steps ;
}
int main(){
int t; cin>>t;
while(t--){
int n; cin>>n;
ld arr_x[n],arr_y[n];
ld h,k;
for(int i=0;i<n;i++){
cin >>arr_x[i];
}
for(int i=0;i<n;i++){
cin >> arr_y[i];
}
int min_steps=INT_MAX;
for(int i=0;i<n;i++){
for(int l=0;l<n;l++){
// mean point
h=(arr_x[i]+arr_x[l])/2;
k=(arr_y[i]+arr_y[l])/2;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
// x&y intersection point
h= arr_x[i];
k=arr_y[l];
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
ld c1=arr_x[i]+arr_y[i];
ld c2=arr_x[l]-arr_y[l];
h = (c1+c2)/2;
k = (c1-c2)/2;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
ld c3 = arr_x[i]+arr_y[i];
h = arr_x[l];
k=c3-h;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
ld c4 = arr_x[i] + arr_y[i];
k = arr_y[l];
h = c4 - k;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
ld c5 = arr_x[i] - arr_y[i];
h = arr_x[l];
k = h - c5;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
ld c6 = arr_x[i] - arr_y[i];
k = arr_y[l];
h = c6 + k;
min_steps=min(min_steps,check(h,k,arr_x,arr_y,n));
}
}
cout << min_steps << endl;
}
return 0;
}