注意到:
1. 点的总数是偶数 ;
2. |xi,yi| ≤1000,点的坐标的绝对值的范围不超过1000;
3. 输出的点的坐标的绝对值的范围不超过1e9.
思路:对所有点排序,找到中间的点(偏左或偏右都可以),刻画离这个点很近的(右边或左边的)直线。考虑到点的坐标范围和答案的坐标范围,直线的斜率可以陡峭到满足题目要求,“很近”是可以满足的。
下面的程序选的是中间偏右的点a[n/2](a[] indexed from 0),刻画的直线是此点左边离此点很近的一条直线。如何保证直线在此点左边?过点(a[n/2].x-1, a[n/2].y+INF)和(a[n/2].x+1, a[n/2].y-INF)的直线经过此点(此点是该直线的中点),过点(a[n/2].x-1, a[n/2].y+INF)和(a[n/2].x+1, a[n/2].y-INF-1)的直线则在此点的左边。
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int INF=99999999;
struct node{
int x, y;
}a[N];
bool cmp(node a,node b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main(){
int t;
while(scanf("%d",&t)!=EOF){
while(t--){
int n;
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
printf("%d %d %d %d\n",a[n/2].x-1,a[n/2].y+INF,a[n/2].x+1,a[n/2].y-INF-1);
}
}
}