http://poj.org/problem?id=3525

题目大意:给一个逆时针序列的多边形点集,求其中可以画的最大半径的圆的半径。

——————————————————————

二分枚举半径长度,然后将所有的边往内缩半径为r,求是否有内核即可。

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const dl eps=1e-;
const int N=;
struct Point{
dl x;
dl y;
}p[N],point[N],q[N],z;
//point,初始点
//q,暂时存可行点
//p,记录可行点
int n,curcnt,cnt;
//curcnt,暂时存可行点个数
//cnt,记录可行点个数
inline Point getmag(Point a,Point b){
Point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline dl multiX(Point a,Point b){
return a.x*b.y-b.x*a.y;
}
inline void getline(Point x,Point y,dl &a,dl &b,dl &c){
a=y.y-x.y;
b=x.x-y.x;
c=y.x*x.y-x.x*y.y;
return;
}
inline Point intersect(Point x,Point y,dl a,dl b,dl c){
Point s;
dl u=fabs(a*x.x+b*x.y+c);
dl v=fabs(a*y.x+b*y.y+c);
s.x=(x.x*v+y.x*u)/(u+v);
s.y=(x.y*v+y.y*u)/(u+v);
return s;
}
inline void cut(dl a,dl b,dl c){
curcnt=;
for(int i=;i<=cnt;i++){
if(a*p[i].x+b*p[i].y+c>-eps)q[++curcnt]=p[i];
else{
if(a*p[i-].x+b*p[i-].y+c>eps){
q[++curcnt]=intersect(p[i],p[i-],a,b,c);
}
if(a*p[i+].x+b*p[i+].y+c>eps){
q[++curcnt]=intersect(p[i],p[i+],a,b,c);
}
}
}
for(int i=;i<=curcnt;i++)p[i]=q[i];
p[curcnt+]=p[];p[]=p[curcnt];
cnt=curcnt;
return;
}
inline void init(){
for(int i=;i<=n;i++)p[i]=point[i];
z.x=z.y=;
p[n+]=p[];
p[]=p[n];
cnt=n;
return;
}
inline void regular(){//调换方向
for(int i=;i<(n+)/;i++)swap(point[i],point[n-i]);
return;
}
inline bool solve(dl r){
init();
for(int i=;i<=n;i++){
Point ta,tb,tt;
tt.x=point[i+].y-point[i].y;
tt.y=point[i].x-point[i+].x;
dl k=r/sqrt(tt.x*tt.x+tt.y*tt.y);
tt.x*=k;tt.y*=k;
ta.x=point[i].x+tt.x;
ta.y=point[i].y+tt.y;
tb.x=point[i+].x+tt.x;
tb.y=point[i+].y+tt.y;
dl a,b,c;
getline(ta,tb,a,b,c);
cut(a,b,c);
}
return cnt;
}
int main(){
while(scanf("%d",&n)!=EOF&&n){
for(int i=;i<=n;i++){
scanf("%lf%lf",&point[i].x,&point[i].y);
}
regular();
point[n+]=point[];
dl l=,r=;
while(fabs(l-r)>eps){
dl mid=(l+r)/2.0;
if(solve(mid))l=mid;
else r=mid;
}
printf("%.6f\n",l);
}
return ;
}

POJ3525:Most Distant Point from the Sea——题解的更多相关文章

  1. poj3525 Most Distant Point from the Sea

    题目描述: vjudge POJ 题解: 二分答案+半平面交. 半径范围在0到5000之间二分,每次取$mid$然后平移所有直线,判断半平面交面积是否为零. 我的eps值取的是$10^{-12}$,3 ...

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

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

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

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

  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. POJ 3525 Most Distant Point from the Sea [半平面交 二分]

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

  6. 【POJ】【3525】Most Distant Point from the Sea

    二分+计算几何/半平面交 半平面交的学习戳这里:http://blog.csdn.net/accry/article/details/6070621 然而这题是要二分长度r……用每条直线的距离为r的平 ...

  7. POJ 3525/UVA 1396 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 ...

  8. POJ3525-Most Distant Point from the Sea(二分+半平面交)

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

  9. 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 ...

随机推荐

  1. Drupal 判断匿名用户必须先登录的解决方法

    要实现如果是匿名用户点击checkout链接,要求先登录 方案一.通过添加Rules规则实现 EVENT:After adding a product to the cart Conditions : ...

  2. hive 优化

    参考: http://www.csdn.net/article/2015-01-13/2823530 http://www.cnblogs.com/smartloli/p/4288493.html h ...

  3. windows安装logstash-input-jdbc并使用其导入MMSQL数据

    1.安装logstash 2.修改logstash 文件夹下Gemfile文件 将source改为:https://gems.ruby-china.org 3.进入bin目录 执行logstash-p ...

  4. MySQL日期比较

    假如有个表product有个字段add_time,它的数据类型为datetime,有人可能会这样写sql: select * from product where add_time = '2013-0 ...

  5. Qt-QML-Popup,弹层界面编写

    随着接触Qt的时间的增加,也逐渐的发现了Qt 的一些不人信话的一些地方,不由的想起一句话,也不知道是在哪里看到的了“一切变成语言都是垃圾,就C++还可以凑合用”大致意思是这样.最近项目的祝界面框架都基 ...

  6. Pandas dataframe数据写入文件和数据库

    转自:http://www.dcharm.com/?p=584 Pandas是Python下一个开源数据分析的库,它提供的数据结构DataFrame极大的简化了数据分析过程中一些繁琐操作,DataFr ...

  7. hive创建外部表

    Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment], ...)] ...

  8. [leetcode-667-Beautiful Arrangement II]

    Given two integers n and k, you need to construct a list which contains n different positive integer ...

  9. 基础数据类型-dict

    字典Dictinary是一种无序可变容器,字典中键与值之间用“:”分隔,而与另一个键值对之间用","分隔,整个字典包含在{}内: dict1 = {key1:value1, key ...

  10. 【转】redis安装与配置

    一.安装 1.官方:http://www.redis.cn/download.html 2.下载.解压.编译 wget http://download.redis.io/releases/redis- ...