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

 #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. keystone系列二:keystone源码分析

    六 keystone架构 6.1 Keystone API Keystone API与Openstack其他服务的API类似,也是基于ReSTFul HTTP实现的. Keystone API划分为A ...

  2. SQL查询数据库表字段值不为空或Null的所有列

    ) set @TableName = 'Agency' -- 表名 declare @querySql nvarchar(max) set @querySql = 'select ' ) declar ...

  3. java 静态方法

    在使用java的时候,你会发现,有些对象,需要new ,有些则不需要时,比如Math类 ); 如果你查看源码就会大致的发现,里面的属性和方法都是静态的: public static double si ...

  4. 首页的sitecontent地址

    当无法出现工具栏时,利用url地址,可以方便直接进入sitecontent http://sp2013/sites/bentest/_layouts/15/viewlsts.aspx

  5. html-----015---HTML ASCII 参考手册

    HTML 和 XHTML 用标准的 7 比特 ASCII 代码在网络上传输数据. 7 比特 ASCII 代码可提供 128 个不同的字符值. 7 比特 可显示的 ASCII 代码 <html&g ...

  6. 伪Base16的构思和实现

    最近看见了一个迅雷地址,发现将其转换为普通链接的工具后,发现所谓专用地址地址就是原地址前加一个表示迅雷的前缀,后进行Base64编码.查阅Base64编码过程后,突发奇想:能否做一个Base16算法? ...

  7. ReactNative-----环境搭建(android)

    1.参考文档 http://reactnative.cn/docs/0.26/getting-started.html http://reactnative.cn/docs/0.26/running- ...

  8. POJ 3254 Corn Fields(DP + 状态压缩)

    题目链接:http://poj.org/problem?id=3254 题目大意:Farmer John 放牧cow,有些草地上的草是不能吃的,用0表示,然后规定两头牛不能相邻放牧.问你有多少种放牧方 ...

  9. UVA 10795 A Different Task(汉诺塔 递归))

    A Different Task The (Three peg) Tower of Hanoi problem is a popular one in computer science. Briefl ...

  10. LA 3708 Graveyard(推理 参考系 中位数)

    Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...