[凸包最大内接圆 二分 半平面交] POJ 3525 Most Distant Point from the Sea

二分答案 然后半平面向内缩 判断是否有交

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double ld;

const double eps=1e-7;

inline int sgn(ld a){
  if (fabs(a)<eps) return 0; if (a<0) return -1; return 1;
}

const int N=105;
const double PI=acos(-1.0);

struct P{
  ld x,y;
  P(ld x=0,ld y=0):x(x),y(y) { }
  ld dist(){ return sqrt(x*x+y*y); }
  P rot(double A){ return P(x*cos(A)-y*sin(A),x*sin(A)+y*cos(A)); }
  friend P operator + (P A,P B) { return P(A.x+B.x,A.y+B.y); }
  friend P operator - (P A,P B) { return P(A.x-B.x,A.y-B.y); }
  friend ld operator * (P A,P B) { return A.x*B.y-B.x*A.y; }
  friend P operator * (P A,ld B) { return P(A.x*B,A.y*B); }
  friend P operator / (P A,ld B) { return P(A.x/B,A.y/B); }
}p[N]; int n;
struct Tl{
  P p1,p2; ld ang;
  Tl() { }
  Tl(P _p1,P _p2){ p1=_p1,p2=_p2; ang=atan2(p2.y-p1.y,p2.x-p1.x); }
  friend bool operator < (const Tl &A,const Tl &B){
    return !sgn(A.ang-B.ang)?((A.p1-B.p1)*(B.p2-B.p1)<0):sgn(A.ang-B.ang)<0;
  }
  friend P cross(const Tl &A,const Tl &B){
    ld ta=(A.p1-B.p1)*(A.p2-B.p1),tb=(A.p2-B.p2)*(A.p1-B.p2);
    return (B.p1*tb+B.p2*ta)/(ta+tb);
  }
}L[N]; int tot;

inline bool onleft(Tl A,Tl B,Tl C){
  P p=cross(A,B);
  return sgn((p-C.p1)*(C.p2-C.p1))<0;
}

int Q[N],l,r;

inline bool hpi(){
  sort(L+1,L+tot+1); int p=1;
  for (int i=2;i<=tot;i++) if (sgn(L[i].ang-L[i-1].ang)) L[++p]=L[i];
  tot=p;
  l=1; r=0; Q[++r]=1;
  for (int i=2;i<=tot;i++){
    while (l<r && !onleft(L[Q[r]],L[Q[r-1]],L[i])) r--;
    while (l<r && !onleft(L[Q[l]],L[Q[l+1]],L[i])) l++;
    Q[++r]=i;
  }
  while (l<r && !onleft(L[Q[r]],L[Q[r-1]],L[Q[l]])) r--;
  while (l<r && !onleft(L[Q[l]],L[Q[l+1]],L[Q[r]])) l++;
  return r-l>=2;
}

inline bool check(ld mid){
  tot=0;
  for (int i=1;i<n;i++) L[++tot]=Tl(p[i],p[i+1]);
  L[++tot]=Tl(p[n],p[1]);
  for (int i=1;i<=tot;i++){
    P tmp=L[i].p2-L[i].p1;
    tmp=tmp.rot(PI/2);
    tmp=tmp/tmp.dist()*mid;
    L[i].p1=L[i].p1+tmp;
    L[i].p2=L[i].p2+tmp;
  }
  return hpi();
}

int main(){
  double x,y;
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  while (1){
    scanf("%d",&n); if (!n) break;
    for (int i=1;i<=n;i++) scanf("%lf%lf",&x,&y),p[i].x=x,p[i].y=y;
    ld L=0,R=50000,MID;
    while (R-L>eps)
      if (check(MID=(L+R)/2))
    L=MID;
      else
    R=MID;
    printf("%.6lf\n",(double)(L+R)/2);
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值