链接

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

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

二分距离,每次让每条边向内推进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. 使用Xcode和Instruments调试解决iOS内存泄露

    转载自:http://www.uml.org.cn/mobiledev/201212123.asp  (或者http://www.cocoachina.com/bbs/read.php?tid=129 ...

  2. ug-Assertion failure in [MyClass layoutSublayersOfLayer:]

    这是在iOS7上,tableview 的sectionHeaderView中报错 *** Assertion failure in -[****.****UITVSectionHeader_Team ...

  3. symfony中twig的模板过滤器

    过滤器 变量可以被过滤器修饰.过滤器和变量用(|)分割开.过滤器也是可以有参数的.过滤器也可以被多重使用. 通用过滤器 date过滤器 1.1版本新增时区支持,1.5版本增加了默认的日期格式.格式化时 ...

  4. mysql 段错误 (core dumped)

    一直使用好好的mysql命令,突然今天抽风,无论使用任何mysql选项都报“段错误 (core dumped)”,以为是mysqld程序出问题了,所以我尝试重启,因为我的环境上是多实例,用了mysql ...

  5. asp.net学习资料,mvc学习资料

    http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/adding-validation-to-the-model

  6. WPFの exit()和close()两个方法的用法

    Application.Exit   方法     通知所有消息泵必须终止,并且在处理了消息以后关闭所有应用程序窗口. Form.Close   方法 关闭窗体. 如果该窗体是应用程序的主启动窗体,则 ...

  7. 零零碎碎写的shell脚本(二):一键修改网络配置信息脚本

    #!/bin/bash ip_mod=$ mask_mod=$ gw_mod=$ dns_mod=$ hostname_mod=$ hosts=/etc/hosts ifcfg=/etc/syscon ...

  8. CentOS系统识别NTFS分区的移动硬盘

    第一步:下载rpmforge,下载对应的版本,就是对应CentOS版本,还有32位与64位也要对应上.rpmforge拥有4000多种CentOS的软件包,被CentOS社区认为是最安全也是最稳定的一 ...

  9. 进程间通信之打开关闭一个exe文件

    一.打开 1.WinExec("F:\\QQ\\Bin\\QQ.exe",SW_SHOW); 注意:'\'需要改成'\\',阻塞 2. STARTUPINFO si; PROCES ...

  10. 【leetcode❤python】191. Number of 1 Bits

    #-*- coding: UTF-8 -*- class Solution(object):    def hammingWeight(self, n):        if n<=0:retu ...