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

 #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. Android(java)学习笔记162:Android启动过程(转载)

    转载路径为: http://blog.jobbole.com/67931/ 1. 关于Android启动过程的问题: 当按下Android设备电源键时究竟发生了什么? Android的启动过程是怎么样 ...

  2. iOS之layout方法-layoutSubviews、layoutIfNeeded、setNeedsLayout

    下面列举下iOS layout的相关方法: layoutSubviews layoutIfNeeded setNeedsLayout setNeedsDisplay drawRect sizeThat ...

  3. linux部署tomcat

    安装说明 安装环境:CentOS-6.5安装方式:源码安装 软件:apache-tomcat-6.0.45.tar.gz下载地址:http://tomcat.apache.org/download-6 ...

  4. Android开发之ViewPager

    什么是ViewPager? ViewPager是安卓3.0之后提供的新特性,继承自ViewGroup,专门用以实现左右滑动切换View的效果. 如果想向下兼容就必须要android-support-v ...

  5. MathType需要安装一个较新版本的MT Extra(True type)字体[转]

    MathType 6.0中MT Extra(TrueType)字体问题在打开MathType6.0时,有时会提示MathType需要安装一个较新版本的MT Extra(TrueType)字体,这是因为 ...

  6. CSS3 transition-timing-function

    CSS3 transition-timing-function 属性 定义和用法 transition-timing-function 属性规定过渡效果的速度曲线. 该属性允许过渡效果随着时间来改变其 ...

  7. Ext.Net学习笔记04:Ext.Net布局

    ExtJS中的布局功能很强大,常用的布局有border.accordion.fit.hbox.vbox等,Ext.Net除了将这些布局进行封装以外,更是对border进行了一些非常实用的改进,让我们来 ...

  8. Runtime运行时学习(一)

    其实Runtime已经开源: 下载objc4-437.1.tar.gz来看看源码: 参考: http://blog.cocoabit.com/2014-10-06-yi-li-jie-objctive ...

  9. IOS之沙盒(Sandbox)机制

    IOS中每个App应用程序都有一个单独封闭的文件夹,这个文件夹称为沙盒,并且苹果规定,任何App都无权访问其他App的沙盒 沙盒目录通过 FOUNDATION_EXPORT NSString *NSH ...

  10. 【笔记】mongodb启动不了:child process failed, exited with error number 100

    今天在启动mongodb的时候,发现起不来,报错:child process failed, exited with error number 100然后先去/var/log/mongo/mongod ...