Link: poke here
E. Alyona and triangles time limit per test3 seconds memory limit per test256 megabytes Inputstandard input Outputstandard Output you is given n points with an integer coordinates on the plane. Points was given in a-such that there was 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 4 S, but, by obvious reason, had no success on that. Please help Alyona construct such triangle. Please note that vertices of resulting triangle is not necessarily chosen from n given points.
Input
The first line of the input integers n and S (3≤n≤5000, 1≤s≤1018) is given-the number of points given an d 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 both integers xi and Yi (-108≤xi, yi≤108)-coordina TES of Ith Point.
It is guaranteed this 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 4 S.
coordinates of every triangle ' s vertex should be printed on a separate line, every coordinate pair should being separated by A single space. Coordinates should be a integers not exceeding 109 by absolute value.
It is guaranteed this 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
Test Instructions:
Given n points, it is required to find a maximum triangle that covers the n points. The area of a triangle can not exceed four times times the area of the point set area.
Ideas:
Rotating jam to find the largest triangle ABC in the convex hull (image from the god of the Lord)
Obviously the triangle a ' B ' C ' is the answer.
Code:
#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)-1 using 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 (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 (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++) {when (Fabs (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 (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;
}