H-Magic Line_2019 cattle off summer school and more training camp (third)

Topic connection:

https://ac.nowcoder.com/acm/contest/883/H

Description

There are always some problems that seem simple but is difficult to solve.

ZYB got N distinct points on a two-dimensional plane. He wants to draw a magic line so that the points will be divided into two parts, and the number of points in each part is the same. There is also a restriction: this line can not pass through any of the points.

Help him draw this magic line.

Input

There are multiple cases. The first line of the input contains a single integer \(T(1<=T<=1000)\), indicating the number of cases.

For each case, the first line of the input contains a single even integer \(N (2 <= N <= 1000)\), the number of points. The following \(N\) lines each contains two integers xi,yi |(xi,yi)| <= 1000, denoting the x-coordinate and the y-coordinate of the -th point.

It is guaranteed that the sum of N over all cases does not exceed 2*10^5.

Output

For each case, print four integers \(x_1, y_1, x_2, y_2\) in a line, representing a line passing through \((x_1, y_1)\) and$ (x_2, y_2)$. Obviously the output must satisfy .

The absolute value of each coordinate must not exceed \(10^9\). It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

Sample Input

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

Sample Output

-1 999000000 1 -999000001

Hint

The meaning of problems

With n integer coordinate points on the two-dimensional plane, obtains a straight line points in the plane into two parts of equal number, and not a bit line, an output line of two points to determine the line

answer:

First take a prime number in the lower left coordinate point at infinity (x, y) for the sorting point and a polar angle of n points, located after the midpoint coordinates sorted (a, b) connecting the two points will point is divided into two parts of equal number, taking the lower-left corner point of symmetry about the midpoint of (a + ax, b + by ), then the left one one lattice point become (2a-x-1, 2b -y)
the (x, y) (2a- x-1, 2b-y) points determined by dividing point of the straight line can be in two parts, and the bit line does not

Code

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX=100005;
const int INF=999999;
typedef long long ll;

int n,top;
struct Node
{
       ll x,y;
}p[MAX],S[MAX];
ll Cross(Node a,Node b,Node c)
{
       return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
  
ll dis(Node a,Node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
 bool cmp(Node a,Node b)
{  
   ll flag = Cross(p[1],a,b);
   if(flag != 0) return flag > 0;
   return dis(p[1],a) < dis(p[1],b); 
}
  
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        p[1].x = -400000009; p[1].y = -2e3;
 
        for(int i=1;i<=n;i++)
            scanf("%lld%lld",&p[i+1].x,&p[i+1].y);
        n++;
        sort(p+2, p+1+n, cmp);
         
        int pos = n/2 + 1;
        ll a = p[pos].x - p[1].x + p[pos].x-1;
        ll b = p[pos].y - p[1].y + p[pos].y;
 
        printf("%lld %lld %lld %lld\n", p[1].x, p[1].y, a, b);
    }
}

Guess you like

Origin www.cnblogs.com/bpdwn-cnblogs/p/11247943.html