链接

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

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

二分距离,每次让每条边向内推进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. socket的心跳包机制

    网络中的接收和发送数据都是使用操作系统中的SOCKET进行实现.但是如果此套接字已经断开,那发送数据和接收数据的时候就一定会有问题.可是如何判断这个套接字是否还可以使用呢?这个就需要在系统中创建心跳机 ...

  2. 记得ajax中要带上AntiForgeryToken防止CSRF攻击

    经常看到在项目中ajax post数据到服务器不加防伪标记,造成CSRF攻击 在Asp.net Mvc里加入防伪标记很简单在表单中加入Html.AntiForgeryToken()即可. Html.A ...

  3. HDU-1042 N!

    首先明白这是大数问题,大数问题大多采用数组来实现.如何进位.求余等.比如1047 (Integer Inquiry): 对于1042问题 计算10000以内数的阶乘,因为10000的阶乘达到35660 ...

  4. Python 中translate()与replace()区别

    translate函数和replace函数一样,用于替换字符串中的某个部分,但是和replace不同,translate只处理单个字符,而且可以同时进行多个替换.在使用translate函数转换之前, ...

  5. Javascript中自动切换焦点

      <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title&g ...

  6. ds.Merge 与 ds.Tables[0].Merge 的用法

    DataSet ds = new DataSet(); SqlConnection conn = new SqlConnection(ConnectionStr);            SqlCom ...

  7. U3D刚体测试2(ForceMode,AddForce,RelativeAddForce)

    摘自圣典的一段翻译: ForceAdd a continuous force to the rigidbody, using its mass.添加一个可持续力到刚体,使用它的质量.Accelerat ...

  8. FlashFXP命令行

    flashfxp.exe -upload ftp://user:pass@ip:port -localpath="本地路径"  -remotepath="远程FTP上的路 ...

  9. asp.net MVC4 lognet4 日志

    asp.net MVC4 lognet4 日志 步骤: 1.引入log4net.dll 2.写配置文件 web.config 加入 如下代码 在<configSections> 中加入&l ...

  10. WCF 自托管、无配置文件实现jsonp(跨域)的访问

    以下内容基于WCF4.0,本文将对比讨论配置文件方案和无配置文件方案的实现方式. WCF4.0加入了对RESTFU和标准终结点的支持,这为实现跨域提供了简单的方式. 一.有配置文件的情况: 首先我们先 ...