版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuxiaowu547/article/details/82153241
求凸多边形的宽度;
凸多边形的宽度就是凸多边形的最短对踵点;
#include<bits/stdc++.h>
using namespace std;
const int N=115;
int n;
double ans=1e100;
struct P
{
int x,y;
P() {}
P(int _x,int _y)
{
x=_x,y=_y;
}
P operator-(P b)
{
return P(x-b.x,y-b.y);
}
double len()
{
return hypot(x,y);
}
} a[N];
double cross(P a,P b)
{
return a.x*b.y-a.y*b.x;
}
double dist(P p,P a,P b)
{
return cross(p-a,b-a)/(b-a).len();
}
void solve()
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j < i; j++)
{
double l=1e100,r=-1e100;
for(int k = 1; k <= n; k++)
{
l=min(l,dist(a[k],a[i],a[j]));
r=max(r,dist(a[k],a[i],a[j]));
}
r-=l;
ans=min(ans,r);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++) scanf("%d %d",&a[i].x,&a[i].y);
solve();
printf("%.10f\n",ans);
return 0;
}