首先矩形的宽度对答案是单峰的
固定宽度 左端点对最大面积也是单峰的
然后三分套三分就好了
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef double ld;
typedef pair<ld,ld> abcd;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const ld eps=1e-10;
inline int sgn(ld x){
if (fabs(x)<eps) return 0;
return x<0?-1:1;
}
const int N=100005;
struct PP{
ld x,y;
PP(ld x=0,ld y=0):x(x),y(y) { }
void read(){ int _x,_y; ::read(_x); ::read(_y); x=_x; y=_y; }
bool operator < (const PP &B) const{
return sgn(x-B.x)<0;
}
};
int n,lp,rp;
PP p[N];
PP a[N],b[N]; int na,nb;
ld X1,X2,Y1,Y2;
inline ld calc(PP p1,PP p2,ld x){
return p1.y+(p2.y-p1.y)*(x-p1.x)/(p2.x-p1.x);
}
inline abcd Calc(ld x){
int it1=upper_bound(a+1,a+na+1,PP(x,0))-a; it1=min(it1,na);
int it2=upper_bound(b+1,b+nb+1,PP(x,0))-b; it2=min(it2,nb);
return abcd(calc(a[it1-1],a[it1],x),calc(b[it2-1],b[it2],x));
}
ld wid;
inline ld f(ld lx){
ld rx=lx+wid;
abcd t1=Calc(lx),t2=Calc(rx);
Y1=max(t1.first,t2.first); Y2=min(t1.second,t2.second);
return min(t1.second,t2.second)-max(t1.first,t2.first);
}
inline ld F(ld wid){
::wid=wid;
ld L=p[lp].x,R=p[rp].x-wid;
while (R-L>1e-6)
if (f((L+L+R)/3)<f((L+R+R)/3))
L=(L+L+R)/3;
else
R=(L+R+R)/3;
X1=L,X2=L+wid;
return f((L+R)/2)*wid;
}
int main(){
freopen("easy.in","r",stdin);
freopen("easy.out","w",stdout);
read(n);
for (int i=1;i<=n;i++) p[i].read();
lp=1,rp=1;
for (int i=1;i<=n;i++){
if (sgn(p[i].x-p[lp].x)<0 || (sgn(p[i].x-p[lp].x)==0 && sgn(p[i].y-p[lp].y)<0))
lp=i;
if (sgn(p[i].x-p[rp].x)>0 || (sgn(p[i].x-p[rp].x)==0 && sgn(p[i].y-p[rp].y)<0))
rp=i;
}
for (int i=lp;;i=i==1?n:i-1){
a[++na]=p[i];
if (i==rp) break;
}
lp=1,rp=1;
for (int i=1;i<=n;i++){
if (sgn(p[i].x-p[lp].x)<0 || (sgn(p[i].x-p[lp].x)==0 && sgn(p[i].y-p[lp].y)>0))
lp=i;
if (sgn(p[i].x-p[rp].x)>0 || (sgn(p[i].x-p[rp].x)==0 && sgn(p[i].y-p[rp].y)>0))
rp=i;
}
for (int i=lp;;i=i==n?1:i+1){
b[++nb]=p[i];
if (i==rp) break;
}
ld L=0,R=p[rp].x-p[lp].x;
while (R-L>1e-6)
if (F((L+L+R)/3)<F((L+R+R)/3))
L=(L+L+R)/3;
else
R=(L+R+R)/3;
F((L+R)/2);
printf("%.10lf %.10lf %.10lf %.10lf\n",X1,Y1,X2,Y2);
//printf("%.10lf\n",F((L+R)/2));
return 0;
}