给一个顺序的凸多边形,求若移动每个点最多d使其凹,求min d
(审题是每个点不是一个)
这里无需借助凸包判断,可证明中间点离相邻点连线一定是最近的,所以枚举每个点即可(注意精度)
#include<bits/stdc++.h>
using namespace std;
int n;
double ans=-1;
struct one {
long long x,y;
}ones[1005];
double dis(one a ,one b)
{
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double cross(one a,one b,one c)
{
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
int main ()
{
cin>>n;
for(int i=0;i<n;++i)
{
cin>>ones[i].x>>ones[i].y;
}
for(int i=0;i<n;++i)
{
double disa=dis(ones[(i-1+n)%n],ones[(i+1)%n]);
disa*=2;
double ans1=0;
ans1=cross(ones[i],ones[(i-1+n)%n],ones[(i+1)%n])/disa;
ans1=fabs(ans1);
if(ans==-1)
ans=ans1;
else ans=min(ans,ans1);
}
printf("%.8lf",ans);
return 0;
}