题目链接

题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少。

思路 :先二分半径r,半平面交向内推进r。模板题

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
const double eps = 1e- ; using namespace std ; struct node
{
double x;
double y ;
} p[],temp[],newp[];//p是最开始的多边形的每个点,temp是中间过程中临时存的多边形的每个点,newp是切割后的多边形的每个点
int n,newn ;//原来的点数,切割后的点数
double a,b,c ;//直线方程的三个系数 void getline(node x,node y)//求x与y两点确定的直线方程ax+by+c=0
{
a = y.y-x.y ;
b = x.x-y.x ;
c = y.x*x.y - y.y*x.x ;
}
node intersect(node x,node y)//求x与y点确定的直线与ax+by+c=0这条直线的交点
{
double u = fabs(a*x.x+b*x.y+c) ;
double v = fabs(a*y.x+b*y.y+c) ;
node t ;
t.x = (x.x*v+y.x*u)/(u+v) ;//y.y-x.y=u+v;y.y-t.y=v;y.y-x.y=u;
t.y = (x.y*v+y.y*u)/(u+v) ;
return t ;
}
void cut()
{
int cutn = ;
for(int i = ; i <= newn ; i++)
{
if(a*newp[i].x+b*newp[i].y+c >= )//所有的点都大于0,说明所有的点都在这条直线的另一边,所以不用切
temp[ ++cutn] = newp[i] ;
else
{
if(a*newp[i-].x+b*newp[i-].y+c > )
temp[++cutn ] = intersect(newp[i-],newp[i]) ;//把新交点加入
if(a*newp[i+].x+b*newp[i+].y+c > )
temp[ ++cutn] = intersect(newp[i+],newp[i]) ;
}
}
for(int i = ; i <= cutn ; i++)
newp[i] = temp[i] ;
newp[cutn+] = temp[] ;//能够找出所有点的前驱和后继
newp[] = temp[cutn] ;
newn = cutn ;
}
double dist(double x,double y)
{
return sqrt(x*x+y*y) ;
}
bool solve(double r)
{
for(int i = ; i <= n ; i++)
{
newp[i] = p[i] ;
}
p[n+] = p[] ;
newp[n+] = newp[] ;
newp[] = newp[n] ;
newn = n ;
for(int i = ; i <= n ; i++)
{
node t1,t2,t ;
t.x = p[i+].y-p[i].y ;
t.y = p[i].x-p[i+].x ;
double k = r/dist(t.x,t.y) ;
t.x *= k ;
t.y *= k ;
t1.x = t.x+p[i].x ;
t1.y = t.y+p[i].y ;
t2.x = t.x+p[i+].x ;
t2.y = t.y+p[i+].y ;
getline(t1,t2) ;//从头开始顺序遍历两个相邻点。
cut() ;
}
if(newn == )
return false ;
else return true ;
//求多边形核的面积
// double s = 0 ;
// for(int i = 1 ; i <= newn ; i++)
// s += newp[i].x*newp[i+1].y-newp[i].y*newp[i+1].x ;
// return s = fabs(s/2.0) ;
}
void guizhenghua()
{
for(int i = ; i < (n+)/ ; i++)//规整化方向,顺时针变逆时针,逆时针变顺时针。
swap(p[i],p[n-i]) ;
}
int main()
{
while(scanf("%d",&n)!=EOF && n)
{
for(int i = ; i <= n ; i++)
scanf("%lf %lf",&p[i].x,&p[i].y) ;
guizhenghua();
p[n+] = p[] ;
double high = ,low = 0.0,mid ;
while(high-low >= eps)
{
mid = (low+high)/2.0 ;
if(solve(mid)) low = mid ;
else high = mid ;
}
printf("%lf\n",high) ;
}
return ;
}

POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)的更多相关文章

  1. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5153   ...

  2. POJ 3525 Most Distant Point from the Sea (半平面交)

    Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...

  3. POJ 3525 Most Distant Point from the Sea

    http://poj.org/problem?id=3525 给出一个凸包,要求凸包内距离所有边的长度的最小值最大的是哪个 思路:二分答案,然后把凸包上的边移动这个距离,做半平面交看是否有解. #in ...

  4. POJ 3525 Most Distant Point from the Sea (半平面交+二分)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3476   ...

  5. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

  6. POJ 3525 Most Distant Point from the Sea 二分+半平面交

    题目就是求多变形内部一点. 使得到任意边距离中的最小值最大. 那么我们想一下,可以发现其实求是看一个圆是否能放进这个多边形中. 那么我们就二分这个半径r,然后将多边形的每条边都往内退r距离. 求半平面 ...

  7. POJ3525 Most Distant Point from the Sea(半平面交)

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

  8. POJ 3384 Feng Shui(半平面交向内推进求最远点对)

    题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...

  9. poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】

    <题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...

随机推荐

  1. ViewPager+Fragment实现滑动显示,且Fragment里面又放Fragment+viewPager

    思路:新建一个Activity,且这个Activity要继承FragementActivity,在Activity的布局文件中放入了一个viewPager,为了效果好看,还做了个导航,使得ViewPa ...

  2. Hi java新特性

    java新特性 1995.5.23 java语言 1996 jdk1.0 250个类在API 主要用在桌面型应用程序1997 jdk1.1 500 图形用户界面编程1998 jdk1.2 2300 J ...

  3. 无法产生coredump的问题

    我写了一个必然会崩溃的程序,名字为 test :#include "stdlib.h"#include "unistd.h" int main(){ char ...

  4. 三星Galaxy Note 10.1 N8010 最后的救赎 Andorid 5.0.2 ROM

    上市日期为2012年的三星Galaxy Note N8010 10.1采用10.1英寸TFT屏幕,分辨率为1280×800,支持10点触控,支持S pen手写笔功能.,拥有一颗1.4GHz Exyno ...

  5. licens 问题 Error (292028): Specified license is not valid for this machine

    集成网卡调试的时候坏了,造成了quartus 不可以用,MAC地址不对应了... 应该怎么解决呢??.

  6. 修改ip脚本

    1.打开运行 2.输入CMD 3.在命令提示符下输入: netsh -c interface ip dump > C:\我的网络配置.txt 4.打开您在C:\ 下的"我的网络配置 . ...

  7. Objective-C面向对象(三)

    1.类的继承 OC的继承是单继承,每个子类只有一个直接父类 1.1 继承的特点 OC继承的语法 @interface SubClass :SuperClass { //成员变量定义 } //方法定义部 ...

  8. 20145103 《Java程序设计》第3周学习总结

    20145103 <Java程序设计>第3周学习总结 教材学习内容总结 第四章我首先了解了CPU与内存的关系,栈与堆的关系.要产生对象必须先定义类,类是对象的设计图,对象是累的实例.以类名 ...

  9. 好书推荐——《Soft Skill》

    这本书不是一本简单的叙述程序员职业规划和如何提高能力的书. 他论述了如何做一个高产,快乐,幸福的程序员,包括职业生涯,理财,学习,健身,信仰等各个方面的内容. 推荐给每一位伟大的拯救宇宙的程序员! 书 ...

  10. An overview of the Spring MVC request flow

    The Spring MVC request flow in short: When we enter a URL in the browser, the request comes to the d ...