半平面的交,二分的方法;

 #include<cstdio>
#include<algorithm>
#include<cmath>
#define eps 1e-6
using namespace std; int dcmp(double x)
{
return fabs(x) < eps ? : (x > ? : -);
} struct Point
{
double x;
double y;
Point(double x = , double y = ):x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Point A, Point B)
{
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B)
{
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p)
{
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p)
{
return Vector(A.x / p, A.y / p);
}
double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
} Vector nomal(Vector a)
{
double l=sqrt(dot(a,a));
return Vector(-a.y/l,a.x/l);
} struct line
{
Point p;
Vector v;
double ang;
line() {}
line(Point p,Vector v):p(p),v(v)
{
ang=atan2(v.y,v.x);
}
bool operator<(const line &t)const
{
return ang<t.ang;
}
}; bool onleft(line l,Point p)
{
return (cross(l.v,p-l.p)>);
} Point getintersection(line a,line b)
{
Vector u=a.p-b.p;
double t=cross(b.v,u)/cross(a.v,b.v);
return a.p+a.v*t;
} int halfplanintersection(line *l,int n,Point *poly)
{
sort(l,l+n);
int first,last;
Point *p=new Point[n];
line *q=new line[n];
q[first=last=]=l[];
for(int i=; i<n; i++)
{
while(first<last && !onleft(l[i],p[last-]))last--;
while(first<last && !onleft(l[i],p[first]))first++;
q[++last]=l[i];
if(fabs(cross(q[last].v,q[last-].v))<eps)
{
last--;
if(onleft(q[last],l[i].p))q[last]=l[i];
}
if(first<last)p[last-]=getintersection(q[last-],q[last]);
}
while(first<last && !onleft(q[first],p[last-]))last--;
if((last-first )<=)return ;
p[last]=getintersection(q[last],q[first]);
int m=;
for(int i=first; i<=last; i++)poly[m++]=p[i];
return m;
} Point p[],poly[];
line l[];
Point v[],v2[];
int main()
{
int n,m;
double x,y;
while(scanf("%d",&n)&&n)
{
for(int i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
p[i]=Point(x,y);
}
for(int i=; i<n; i++)
{
v[i]=p[(i+)%n]-p[i];
v2[i]=nomal(v[i]);
}
double left=0.0,right=20000.0;
while(right-left>eps)
{
double mid=(left+right)/;
for(int i=; i<n; i++)
l[i]=line(p[i]+v2[i]*mid,v[i]);
m=halfplanintersection(l,n,poly);
if(!m)right=mid;
else left=mid;
}
printf("%.6lf\n",left);
}
return ;
}

uva 1396 - Most Distant Point from the Sea的更多相关文章

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

  2. UVA 3890 Most Distant Point from the Sea(二分法+半平面交)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=11358 [思路] 二分法+半平面交 二分与海边的的距离,由法向量可 ...

  3. 1396 - Most Distant Point from the Sea

    点击打开链接 题意: 按顺序给出一小岛(多边形)的点 求岛上某点离海最远的距离 解法: 不断的收缩多边形(求半平面交) 直到无限小 二分收缩的距离即可 如图 //大白p263 #include < ...

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

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

  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

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

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

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

  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. Mac上安装boost开放环境

    方法一: 去Macports官网的下载页面(https://distfiles.macports.org/MacPorts/)下载对用Mac系统的pkg文件,下载完成之后,双击,一路[下一步],到安装 ...

  2. ajax异步传输

    2015.12.7 ajax异步传输 1.ajax :不是一个新的技术. js(XMLHTTPRequest) html css dom xml 这里只是一个新的js的内置对象.这算是js想要变得流行 ...

  3. Nginx高性能服务器安装、配置、运维 (4) —— Nginx服务、架构及其信号

    五.Nginx服务.架构及其信号 (1)Nginx服务的查看 1.netstat -antp 查看Nginx是否在80端口运行: 2.ps aux|grep nginx 查看nginx相关进程: 发现 ...

  4. Java中的编码问题

    下面将侧重介绍java乱码是如何产生的.存在哪些乱码的情况.该如何从根本上解决乱码问题.各位随博主一起征服令人厌烦的java乱码问题吧!!! 一.Java编码转换过程 我们总是用一个java类文件和用 ...

  5. 第十篇:web之前端之django一些feature

    前端之django一些feature   前端之django一些feature 本节内容 cookie session 跨站请求保护 分页 序列化 model模块 CBV和FBV 模板渲染对象 1. ...

  6. php中的全局变量引用

    全局变量在函数外部定义,作用域为从变量定义处开始,到本程序文件的末尾.但和其他语言不同,php的全局变量不是自动设为可用的,在php中函数可以视为单独的程序片段,局部变量会覆盖全局变量的能见度,因此, ...

  7. MVC框架是什么

     MVC (Modal View Controler)本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器.使用MVC的目的是将M和V的实现代码分离,从而使同一个程序可以使 ...

  8. Java集合和PHP的对比

    这里突然感觉到在java中的集合,和php的数组非常相似 .

  9. iis的路径

    每次打开iis管理器查看iis指定路径下的文件过于麻烦,而且iis管理器耗资源,以下是iis的路径,以及其对应在本地磁盘的地址 SP2013\Sites\SharePoint - 80\_contro ...

  10. Js 学习资料

    Js 语法 http://www.php100.com/manual/jquery/   jqGrid控件 http://www.trirand.com/blog/jqgrid/jqgrid.html