题意
求一个最大的距离D,使得一个凸多边形的 n 个顶点无论在D的半径内如何移动,新的多边形 P 每条边均不相交(除了两邻边公共顶点),以及仍是一个凸多边形
思路
一图胜千言:
对于任意三个相邻的顶点,能够”自由活动”的范围不能大于三角形高的一半,不然就可能不是凸多边形了
代码
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
const int INF=0x3f3f3f3f;
const int maxn=1e5+50;
const int mod=1e9+7;
const double eps=1e-8;
#define pii pair<int,int>
typedef long long ll;
typedef unsigned int ui;
using namespace std;
int n;
struct P{
double x,y;
void read(){
scanf("%lf %lf",&x,&y);
}
P() {}
P(double x, double y) : x(x), y(y) {}
P operator-(const P&r){
return P(x-r.x,y-r.y);
}
double cross(const P&r){
return x*r.x+y*r.y;
}
double len(){
return sqrt(x*x+y*y);
}
};
P s[maxn];
double calS(double a,double b,double c){
double p=(a+b+c)/2;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
//int T; scanf("%d",&T);
while(~scanf("%d",&n)){
rep(i,0,n) {
s[i].read();
}
double ans=1e18;
rep(i,0,n){
P v1=s[(i+1)%n]-s[i];
P v2=s[(i-1+n)%n]-s[i];
P v3=s[(i+1)%n]-s[(i-1+n)%n];
double h=calS(v1.len(),v2.len(),v3.len())/v3.len();
ans=min(ans,h);
}
printf("%.10lf\n",ans);
}
return 0;
}