Roughly meaning of the questions:
The number of test input T, the number of inputs n (n is an even number), then the coordinates are inputted n different points, required output four integers x1, y1, x2, y2, expressed through a point (x1 , y1), (x2, y2) of the points in the straight two-dimensional plane into equal portions two points. (This line can not pass through the plane at any point)
sample input:
1
4
0 1
-1 0
1 0
0 -1
sample output:(special judge)
-1 999000000 1 -999000001
answer:
In these n points x and y is the second key to the first key in ascending order, find the middle two points a and b, as a dividing line to the two points, one can always find a and b by steep linear points may be points in the plane into two parts of equal number of points.
If the sorted intermediate a, the x-coordinate of the points a and b are not the same, just one is drawn in a, a straight line between the points a and b are; intermediate sorted if a, as the x-coordinate of the points a and b, it must pass a, b midpoint straight down.
Code:
1 #include<bits/stdc++.h> 2 #define IO ios::sync_with_stdio(false); 3 using namespace std; 4 const int m=99990000; 5 struct point 6 { 7 int x,y; 8 }p[1005]; 9 bool cmp(point s1,point s2) 10 { 11 if(s1.x==s2.x)return s1.y<s2.y; 12 else return s1.x<s2.x; 13 } 14 int main() 15 { 16 IO;int T,n; 17 cin>>T; 18 while(T--) 19 { 20 int x1,y1,x2,y2; 21 cin>>n; 22 for(int i=0;i<n;i++) 23 cin>>p[i].x>>p[i].y; 24 sort(p,p+n,cmp); 25 if(p[n/2].x!=p[n/2-1].x) 26 x1=p[n/2-1].x,y1=m,x2=p[n/2].x,y2=-m; 27 else 28 x1=p[n/2].x-1,y1=p[n/2].y+m,x2=p[n/2].x+1,y2=p[n/2-1].y-m; 29 cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl; 30 } 31 return 0; 32 }