题意: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;
}