题意
给出n个点的坐标,画出一条直线将这些点分开,每边各占一半
题解
将这些点的横坐标排序,如果相等,则排纵坐标的大小,然后在极远处稍微倾斜这条直线,就可以将这些点分开
当两个y相同时,一定过中心点(a[n/2].x, 0),然后向上平移a[n/2].y, 就一定经过点 (a[n/2].x , a[n/2].y), 只需将直线右端点向上平移一点距离,直线就不会过点 (a[n/2].x , a[n/2].y), 将两边完全分开
#include<bits/stdc++.h>
using namespace std;
struct node{
int x, y;
}a[200005];
bool cmp(node k, node u){
if(k.x != u.x){
return k.x < u.x;
}
return k.y < u.y;
}
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
}
sort(a+1, a+1+n, cmp);
cout << a[n/2].x-1 << " " << a[n/2].y+999000000 << " " << a[n/2].x+1 << " " << a[n/2].y-998999999 << endl;
//此处加或减的值要大但要适当,否则会出错
}
return 0;
}