Magic Line (thinking + computational geometry) (more than 2019 cattle off summer school camp (third))

Example:

Input:

1
4
0 1
-1 0
1 0
0 -1

Output: -19990000001 -999 000 001

Meaning of the questions: a series of points on a given plane, in order to find a (x1, y1), (x2 , y2) is represented by two straight lines divide the plane into an equal number of points comprises two parts, a straight line can not pass through any point .

Ideas:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct node
 4 {
 5     int x,y;
 6 };
 7 bool cmp(node p,node q)
 8 {
 9     if(p.x==q.x)return p.y<q.y;
10     else return p.x<q.x;
11 }
12 node a[1020],b[1020];
13 int main()
14 {
15     int T,n;
16     scanf("%d",&T);
17     while(T--)
18     {
19         scanf("%d",&n);
20         for(int i=1; i<=n; i++)
21         {
22             scanf("%d%d",&a[i].x,&a[i].y);
23         }
24         sort(a+1,a+n+1,cmp);//直接对所有的线从左到右排序
25         printf("%d %d %d %d\n",a[n/2].x+1,a[n/2].y-999000000,a[n/2+1].x-1,a[n/2+1].y+999000000);
26     }
27     return 0;
28 }

 

Guess you like

Origin www.cnblogs.com/Aamir-Dan/p/11265258.html