列表

详情


NC51466. Magic Line

描述

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

ZYB got  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.

输入描述

There are multiple cases. The first line of the input contains a single integer , indicating the number of cases. 

For each case, the first line of the input contains a single even integer , the number of points. The following $N$ lines each contains two integers , denoting the x-coordinate and the y-coordinate of the -th point.

It is guaranteed that the sum of  over all cases does not exceed .

输出描述

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 . It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

示例1

输入:

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

输出:

-1 999000000 1 -999000001

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 48ms, 内存消耗: 2400K, 提交时间: 2020-06-21 16:24:19

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int,int>p[1005];
int eps=1e8;
main(){
    int n,t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);
        sort(p,p+n);
        printf("%d %d %d %d\n",p[n/2-1].first+1,p[n/2-1].second-eps,p[n/2].first-1,p[n/2].second+eps);
    }
}

C++11(clang++ 3.9) 解法, 执行用时: 59ms, 内存消耗: 736K, 提交时间: 2019-07-25 20:00:23

#include<bits/stdc++.h>
using namespace std;
pair<int,int> p[1005];
int EPS=8e8;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d %d",&p[i].first,&p[i].second);
		}
		sort(p+1,p+n+1);
		printf("%d %d %d %d\n",p[n/2].first+1,p[n/2].second-EPS,p[n/2+1].first-1,p[n/2+1].second+EPS);
	}
}

上一题