https://cn.vjudge.net/problem/Gym-101606B
要把一块多边形饼干放进一个口子里,问口子直径最小是多少
其实就把多边形求个凸包,然后对于凸包上每一条边,找一个离这条边最远的点的距离,然后这个距离的最小值就是答案
只要把旋转卡壳改一下就行了
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define maxl 110
#define eps 1e-8
using namespace std;
inline int sgn(double x)
{
if(x>-eps && x<eps) return 0;
if(x>0) return 1;
else return -1;
}
struct point
{
double x,y;
point(double a=0,double b=0)
{
x=a,y=b;
}
inline point operator - (const point &b)const
{
return point(x-b.x,y-b.y);
}
inline bool operator == (const point &b)const
{
return sgn(x-b.x)==0 && sgn(y-b.y)==0;
}
inline double norm()
{
return sqrt(x*x+y*y);
}
};
inline double dot(const point &a,const point &b)
{
return a.x*b.x+a.y*b.y;
}
inline double det(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
struct polygon_convex
{
vector<point> P;
polygon_convex(int size=0)
{
P.resize(size);
}
};
inline bool cmp(const point &a,const point &b)
{
if(sgn(a.x-b.x)==0)
return sgn(a.y-b.y)<0;
return sgn(a.x-b.x)<0;
}
polygon_convex convex_hull(vector<point> a)
{
polygon_convex res(2*a.size()+5);
sort(a.begin(),a.end(),cmp);
a.erase(unique(a.begin(),a.end()),a.end());
int m=0,l=a.size();
for(int i=0;i<l;i++)
{
while(m>1 && sgn(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<=0)
--m;
res.P[m++]=a[i];
}
int k=m;
for(int i=l-2;i>=0;i--)
{
while(m>k && sgn(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<=0)
--m;
res.P[m++]=a[i];
}
res.P.resize(m);
if(a.size()>1)
res.P.resize(m-1);
return res;
}
inline double convex_min_dis(polygon_convex &a)
{
vector<point> &p=a.P;
int n=p.size();
double mind=1ll<<62;
if(n==1)
return 0;
#define nxt(i) ((i+1)%n)
for(int i=0,j=1;i<n;i++)
{
while(sgn(det(p[nxt(i)]-p[i],p[j]-p[i])-det(p[nxt(i)]-p[i],p[nxt(j)]-p[i]))<0)
j=nxt(j);
double d=fabs(det(p[j]-p[i],p[j]-p[nxt(i)]))/(p[nxt(i)]-p[i]).norm();
if(d<mind)
mind=d;
}
return mind;
}
int n;
vector<point> a;
polygon_convex res;
double ans;
inline void prework()
{
a.clear();
point p;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&p.x,&p.y);
a.push_back(p);
}
}
inline void mainwork()
{
res=convex_hull(a);
ans=0;int l=res.P.size();
int x,y;
ans=convex_min_dis(res);
}
inline void print()
{
printf("%.8f\n",ans);
}
int main()
{
while(~scanf("%d",&n))
{
prework();
mainwork();
print();
}
return 0;
}