链接

求凸多边形内一点距离边最远。

做法:二分+半平面交判定。

二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核。

本想自己写一个向内推进。。仔细一看发现自己的平面交模板上自带。。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
const int MAXN=;
int m;
double r;
int cCnt,curCnt;//此时cCnt为最终切割得到的多边形的顶点数、暂存顶点个数
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
};
point points[MAXN],p[MAXN],q[MAXN];//读入的多边形的顶点(顺时针)、p为存放最终切割得到的多边形顶点的数组、暂存核的顶点
void getline(point x,point y,double &a,double &b,double &c) //两点x、y确定一条直线a、b、c为其系数
{
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void initial()
{
for(int i = ; i <= m; ++i)p[i] = points[i];
p[m+] = p[];
p[] = p[m];
cCnt = m;//cCnt为最终切割得到的多边形的顶点数,将其初始化为多边形的顶点的个数
}
point intersect(point x,point y,double a,double b,double c) //求x、y形成的直线与已知直线a、b、c、的交点
{
double u = fabs(a * x.x + b * x.y + c);
double v = fabs(a * y.x + b * y.y + c);
point pt;
pt.x=(x.x * v + y.x * u) / (u + v);
pt.y=(x.y * v + y.y * u) / (u + v);
return pt;
}
void cut(double a,double b ,double c)
{
curCnt = ;
for(int i = ; i <= cCnt; ++i)
{
if(a*p[i].x + b*p[i].y + c >= )q[++curCnt] = p[i];// c由于精度问题,可能会偏小,所以有些点本应在右侧而没在,
//故应该接着判断
else
{
if(a*p[i-].x + b*p[i-].y + c > ) //如果p[i-1]在直线的右侧的话,
{
//则将p[i],p[i-1]形成的直线与已知直线的交点作为核的一个顶点(这样的话,由于精度的问题,核的面积可能会有所减少)
q[++curCnt] = intersect(p[i],p[i-],a,b,c);
}
if(a*p[i+].x + b*p[i+].y + c > ) //原理同上
{
q[++curCnt] = intersect(p[i],p[i+],a,b,c);
}
}
}
for(int i = ; i <= curCnt; ++i)p[i] = q[i];//将q中暂存的核的顶点转移到p中
p[curCnt+] = q[];
p[] = p[curCnt];
cCnt = curCnt;
}
int solve(double r)
{
//注意:默认点是顺时针,如果题目不是顺时针,规整化方向
initial();
// for(int i = 1; i <= m; ++i)
// {
// double a,b,c;
// getline(points[i],points[i+1],a,b,c);
// cut(a,b,c);
// } //如果要向内推进r,用该部分代替上个函数
for(int i = ; i <= m; ++i){
point ta, tb, tt;
tt.x = points[i+].y - points[i].y;
tt.y = points[i].x - points[i+].x;
double k = r / sqrt(tt.x * tt.x + tt.y * tt.y);
tt.x = tt.x * k;
tt.y = tt.y * k;
ta.x = points[i].x + tt.x;
ta.y = points[i].y + tt.y;
tb.x = points[i+].x + tt.x;
tb.y = points[i+].y + tt.y;
double a,b,c;
getline(ta,tb,a,b,c);
cut(a,b,c);
}
//多边形核的面积
// double area = 0;
// for(int i = 1; i <= curCnt; ++i)
// area += p[i].x * p[i + 1].y - p[i + 1].x * p[i].y;
// area = fabs(area / 2.0);
// printf("%.2f\n",area);
if(curCnt) return ;
return ; }
void GuiZhengHua(){
//规整化方向,逆时针变顺时针,顺时针变逆时针
for(int i = ; i < (m+)/; i ++)
swap(points[i], points[m-i]);
}
//void change(double d)
//{
// int i;
// for(i = 1; i <= m ;i++)
// {
// double len = dis(p[i],points[i+1]);
// double a = points[i+1].y-points[i].y;
// double b = points[i].x-points[i+1].x;
// double cos = a/len;
// double sin = b/len;
// points[i] = point(points[i].x+cos*d,points[i].y+sin*d);
// points[i+1] = point(points[i+1].x+cos*d,points[i+1].y+sin*d);
// }
//}
int main()
{
int i;
while(scanf("%d",&m)&&m)
{
for(i = ; i<=m; i++)
scanf("%lf%lf",&points[i].x,&points[i].y);
GuiZhengHua();
points[m+] = points[];
double rig = INF,lef = ,mid;
while(rig-lef>eps)
{
mid = (rig+lef)/2.0;
//change(mid);
if(solve(mid))
lef = mid;
else rig = mid;
}
printf("%.6f\n",lef);
}
return ;
}

poj3525Most 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. LA 3890 Most Distant Point from the Sea(半平面交)

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

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

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

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

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

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

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

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

  7. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  8. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  9. POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)

    题目链接 题意 : 给你一个多边形,问你里边能够盛的下的最大的圆的半径是多少. 思路 :先二分半径r,半平面交向内推进r.模板题 #include <stdio.h> #include & ...

随机推荐

  1. HDU 2136:Computer(树形DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 Computer     Description A school bought the fi ...

  2. Spring集成memcached的详细介绍

    前提条件:工程需要引入jar包java_memcached-release_2.0.1.jar 第一步:添加memcached的配置文件. <bean class="org.sprin ...

  3. StringUtils 帮助类所涉及的方法

    /*1.字符串以prefix开始*/StringUtils.startsWith("sssdf","");//结果是:trueStringUtils.start ...

  4. 在Java中导出word、excel格式文件时JSP页面头的设置

    我们在JSP中往往会把一些表格里的东西需要导出到本地,一般都是导成word.excel格式的文件.这只需要在JSP页面头设置及在<head></head>标签中添加下面的代码: ...

  5. c#sqlhelper之用法

    MySqlParameter[] a=new MySqlParameter[]{new MySqlParameter("@stu_id",stu_id)}; 参数使用

  6. 【MySQL】MySQL PLSQL Demo - 006.循环(WHILE DO and FOR LOOP)

    WHILE DO drop procedure if exists p_while_do; create procedure p_while_do() begin declare i int; ; d ...

  7. 工欲善其事必先利其器系列之:在VS里面折叠js代码

    之前用vs写js的时候经常因为js代码过长而且不能像cs文件里面的方法一样进行折叠而抓狂,直到在扩展库发现了这款插件有了它就可以把代码进行折叠了 插件地址

  8. SqlSever基础 top 后面的n 由一个简单的计算式子计算得出

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  9. getElementsByClassName

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. js 定位到某个锚点

    js 定位到某个锚点 html页面内可以设置锚点,锚点定义 <a name="firstAnchor">&nsbp;</a> 锚点使用 <a  ...