Codeforces 682E 计算几何

来源:互联网 发布:caffe 使用训练好模型 编辑:程序博客网 时间:2024/05/21 21:42

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 10 01 00 11 1
output
-1 02 00 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; }


0 0