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.c++
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.spa
Inputcode
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.orm
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.blog
It is guaranteed that there is at least one triple of points not lying on the same line.three
Outputip
Print the coordinates of three points — vertices of a triangle which contains all n points and which area doesn't exceed 4S.input
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
It is guaranteed that there is at least one desired triangle. If there is more than one answer, print any of them.io
Example
4 1
0 0
1 0
0 1
1 1
-1 0
2 0
0 2
題意:給定N個點,保證最大三角形面積不超過S,如今讓你找一個面積不超過4*S的三角形,使之覆蓋全部點。
思路:找到最大三角形X,而後按照平行四邊形的樣子,對稱出3個三角形。便可覆蓋全部點,不然能夠反證X的面積不是最大。
因此按照上一題同樣,先求凸包,而後求最大三角形的座標,而後對稱。 如圖:
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define ll long long #define RC rotating_calipers using namespace std; const int maxn=100010; struct point{ ll x,y; point(ll x=0,ll y=0):x(x),y(y){} bool operator <(const point &c) const { return x<c.x||(x==c.x&&y<c.y);} point operator -(const point &c)const { return point(x-c.x,y-c.y);} }; ll det(point A,point B){ return A.x*B.y-A.y*B.x;} ll det(point O,point A,point B){ return det(A-O,B-O);} point a[maxn],ch[maxn],A,B,C; void convexhull(int n,int &top) { sort(a+1,a+n+1); top=0; for(int i=1;i<=n;i++){ while(top>1&&det(ch[top-1],ch[top],a[i])<=0) top--; ch[++top]=a[i]; } int ttop=top; for(int i=n-1;i>=1;i--){ while(top>ttop&&det(ch[top-1],ch[top],a[i])<=0) top--; ch[++top]=a[i]; } } void rotating_calipers(point p[],int top) { ll ans=0; int now; rep(i,1,top-2){ int now=i+2; rep(j,i+1,top-1){ while(now<=top&&abs(det(p[i],p[j],p[now]))<abs(det(p[i],p[j],p[now+1]))){ now++; } ll tmp=abs(det(p[i],p[j],p[now])); if(tmp>ans) ans=tmp,A=p[i],B=p[j],C=p[now]; } } } int main() { int N; ll S; scanf("%d%I64d",&N,&S); for(int i=1;i<=N;i++) scanf("%I64d%I64d",&a[i].x,&a[i].y); int top; convexhull(N,top); RC(ch,top-1); printf("%I64d %I64d\n",A.x+B.x-C.x,A.y+B.y-C.y); printf("%I64d %I64d\n",A.x+C.x-B.x,A.y+C.y-B.y); printf("%I64d %I64d\n",B.x+C.x-A.x,B.y+C.y-A.y); return 0; }