Codeforces Round #358 (Div. 2) E 計算幾何 旋轉卡殼求最大三角形面積

來源:互聯網
上載者:User



連結:戳這裡


E. Alyona and Triangles time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard 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 ≤ 5000, 1 ≤ 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個點,要求找出一個最大的三角形使得三角形覆蓋這n個點。三角形的面積不能超過四倍的點集地區面積。


思路:

旋轉卡殼求出凸包內最大的三角形ABC(圖片來自卿神)


顯然三角形A'B'C'就是答案。


代碼:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;struct point{    double x,y;    point(double x=0,double y=0):x(x),y(y){}    bool operator < (const point &a)const{        if(x==a.x) return y<a.y;        return x<a.x;    }};const double eps=1e-8;typedef point vec;vec operator + (point a,point b){    return vec(a.x+b.x,a.y+b.y);}vec operator - (point a,point b){    return vec(a.x-b.x,a.y-b.y);}vec operator * (point a,double t){    return vec(a.x*t,a.y*t);}vec operator / (point a,double t){    return vec(a.x/t,a.y/t);}double cross(vec a,vec b){    return a.x*b.y-a.y*b.x;}int dcmp(double x){    if(fabs(x)<=eps) return 0;    return x<0?-1:1;}bool cmp(point a,point b){    if(dcmp(a.x-b.x)==0) return a.y<b.y;    return a.x<b.x;}point p[5010];void convexhull(point *s,int &n){    sort(s,s+n);    ///sort(s,s+n,cmp);    int m=0;    s[n]=s[0];    for(int i=0;i<n;i++){        while(m>1 && dcmp(cross(p[m-1]-p[m-2],s[i]-p[m-2]))<=0)            m--;        p[m++]=s[i];    }    int k=m;    for(int i=n-2;i>=0;i--){        while(m>k && dcmp(cross(p[m-1]-p[m-2],s[i]-p[m-2]))<=0)            m--;        p[m++]=s[i];    }    m--;    n=m;    for(int i=0;i<n;i++) s[i]=p[i];}point s[5010];ll S;int n;int main(){    scanf("%d%I64d",&n,&S);    for(int i=0;i<n;i++) scanf("%lf%lf",&s[i].x,&s[i].y);    convexhull(s,n);    s[n]=s[0];    s[n+1]=s[1];    s[n+2]=s[2];    double sum=0.0;    int ansi=0,ansj=1,ansk=2;    int j=1,k=2;    for(int i=0;i<n;i++){        while(fabs(cross(s[j]-s[i],s[k+1]-s[i]))-fabs(cross(s[j]-s[i],s[k]-s[i]))>=eps)            k=(k+1)%n;        while(fabs(cross(s[k]-s[i],s[j+1]-s[i]))-fabs(cross(s[k]-s[i],s[j]-s[i]))>=eps)            j=(j+1)%n;        double tmp=fabs(cross(s[j]-s[i],s[k]-s[i]));        if(dcmp(tmp-sum)>=0){            ansi=i;            ansj=j;            ansk=k;            sum=tmp;        }    }    point A=s[ansj]+s[ansk]-s[ansi];    point B=s[ansi]+s[ansk]-s[ansj];    point C=s[ansi]+s[ansj]-s[ansk];    printf("%.0f %.0f\n",A.x,A.y);    printf("%.0f %.0f\n",B.x,B.y);    printf("%.0f %.0f\n",C.x,C.y);    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.