Codeforces 682E 计算几何

Alyona and Triangles
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n points with integer coordinates on the plane. Points are given in a way such that there is no triangle, formed by any three of these n points, which area exceeds S.

Alyona tried to construct a triangle with integer coordinates, which contains all n points and which area doesn't exceed 4S, but, by obvious reason, had no success in that. Please help Alyona construct such triangle. Please note that vertices of resulting triangle are not necessarily chosen from n given points.

Input

In the first line of the input two integers n and S (3 ≤ n ≤ 50001 ≤ S ≤ 1018) are given — the number of points given and the upper bound value of any triangle's area, formed by any three of given n points.

The next n lines describes given points: ith of them consists of two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — coordinates of ith point.

It is guaranteed that there is at least one triple of points not lying on the same line.

Output

Print the coordinates of three points — vertices of a triangle which contains all n points and which area doesn't exceed 4S.

Coordinates of every triangle's vertex should be printed on a separate line, every coordinate pair should be separated by a single space. Coordinates should be an integers not exceeding 109 by absolute value.

It is guaranteed that there is at least one desired triangle. If there is more than one answer, print any of them.

Example
input
4 1
0 0
1 0
0 1
1 1
output
-1 0
2 0
0 2
Note


题意:n个点,找出一个三角形,使得包含所有点。


题解:先找出最大三角形的三个点,然后A做关于BC中点对称,B做AC,C做AB。

最大三角形用迭代法,复杂度n2.


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
ll x[5005],y[5005];
ll getArea(ll a,ll b,ll c){
    return abs((x[b]-x[a])*(y[c]-y[a])-(x[c]-x[a])*(y[b]-y[a]));
}
int main(){
	ll i,j,k,s;
    scanf("%lld%lld",&n,&s);
    for(i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&y[i]);
	}
	ll a=1,b=2,c=3;
	while(1){
		ll flag=0;
		for(i=1;i<=n;i++){
			s=getArea(a,b,c);
			if(s<getArea(i,b,c))a=i,flag=1;
			else if(s<getArea(a,i,c))b=i,flag=1;
			else if(s<getArea(a,b,i))c=i,flag=1;
		}
		if(!flag)break;
	}
	cout<<(x[a]+x[b]-x[c])<<" "<<(y[a]+y[b]-y[c])<<endl;
    cout<<(x[a]+x[c]-x[b])<<" "<<(y[a]+y[c]-y[b])<<endl;
    cout<<(x[b]+x[c]-x[a])<<" "<<(y[b]+y[c]-y[a])<<endl;
    return 0; 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值