题目大意:

给定一个多边形,给定一个圆的半径,要求在多边形中放置两个同样半径的圆,可相互覆盖,但不能超出多边形的范围,希望两个圆的面积覆盖和最大

输出任意一组满足的圆的圆心点

如果两个圆不相互覆盖,那么必然达到最大面积

如果相互覆盖,可以换一种方式考虑,因为两个圆是一样的,两个圆的距离越长,那么相互覆盖的面积必然越小

所以可以将多边形内推进半径的长度

然后在半平面交后得到的多边形中找到距离最远的两个点

仔细想一想可以知道多边形上最远距离的点,必然是两个顶点的距离

所以平方的方法就可以求解了

当然用旋转卡壳的话在n的复杂度内就可以完美解决也是可行的

这里就用第一种简单的方法了

这里感觉精度卡的比较严,之前没写dcmp就一直过不了,尝试着加了一些精确度判断就a了

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define N 105
#define eps 1e-9 int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} struct Point{
double x , y;
Point(double x= , double y=):x(x),y(y){}
void input(){scanf("%lf%lf" , &x , &y);}
double dis(Point m){
return (x-m.x)*(x-m.x)+(y-m.y)*(y-m.y);
}
}p[N] , poly[N]; typedef Point Vector; 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 &m) const{
return dcmp(ang-m.ang)<;
}
}line[N]; Vector operator+(Vector a , Vector b){return Vector(a.x+b.x , a.y+b.y);}
Vector operator-(Vector a , Vector b){return Vector(a.x-b.x , a.y-b.y);}
Vector operator*(Vector a , double b){return Vector(a.x*b , a.y*b);}
Vector operator/(Vector a , double b){return Vector(a.x/b , a.y/b);} double Cross(Vector a , Vector b){return a.x*b.y-a.y*b.x;}
double Dot(Vector a , Vector b){return a.x*b.x+a.y*b.y;}
double Len(Vector a){return sqrt(Dot(a , a));} Vector Normal(Vector a)
{
double l = Len(a);
return Vector(-a.y , a.x)/l;
} bool OnLeft(Line L , Point p)
{
return dcmp(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 HalfplaneIntersection(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;
} int n;
double r; int main()
{
// freopen("in.txt" , "r" , stdin);
while(~scanf("%d%lf" , &n , &r)){
for(int i= ; i<n ; i++) p[i].input();
p[n] = p[];
for(int i= ; i<n ; i++){
Vector v = p[i]-p[i+];
Vector t = Normal(v)*r;
line[i] = Line(p[i]+t , v);
}
int k = HalfplaneIntersection(line , n , poly);
Point p1=poly[] , p2=poly[];
double maxn = ;
// for(int i=0 ; i<k ; i++) cout<<poly[i].x<<" "<<poly[i].y<<endl;
for(int i= ; i<k ; i++){
for(int j= ; j<k ; j++){
if(poly[i].dis(poly[j])-maxn>eps){
p1 = poly[i] , p2 = poly[j];
maxn = poly[i].dis(poly[j]);
}
}
}
printf("%.4f %.4f %.4f %.4f\n" , p1.x , p1.y , p2.x , p2.y);
}
return ;
}

POJ 3384的更多相关文章

  1. poj 3384 半平面交

    Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5183   Accepted: 1548   Speci ...

  2. POJ 3384 Feng Shui

    http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...

  3. poj 3384 Feng Shui (Half Plane Intersection)

    3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...

  4. POJ 3384 Feng Shui --直线切平面

    题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠 ...

  5. POJ 3384 Feng Shui(半平面交向内推进求最远点对)

    题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...

  6. POJ 3384 Feng Shui 半平面交

    题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...

  7. POJ 3384 Feng Shui 凸包直径 + 半平面交

    G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...

  8. POJ 3384 放地毯【半平面交】

    <题目链接> 题目大意: 给出一个凸多边形的房间,根据风水要求,把两个圆形地毯铺在房间里,不能折叠,不能切割,可以重叠.问最多能覆盖多大空间,输出两个地毯的圆心坐标.多组解输出其中一个,题 ...

  9. POJ 3384 Feng Shui (半平面交)

    Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3743   Accepted: 1150   Speci ...

随机推荐

  1. iphone 使用技巧

    http://www.app111.com/doc/100147120_1.html(隐藏某个图标) (3)传视频  moliplayer 和itunes  ---应用(在下部)找到moliplaye ...

  2. 使用kaptcha生成验证码

    原文:http://www.cnblogs.com/xdp-gacl/p/4221848.html kaptcha是一个简单好用的验证码生成工具,通过配置,可以自己定义验证码大小.颜色.显示的字符等等 ...

  3. OpenGL的几何变换4之内观察全景图

    上一次写了OpenGL的几何变换3之内观察全景图 上次采用的是图片分割化方式,这次采用数据分割化方式. 先说下思路,数据分割化方式呢,是只读取一张图片imgData,然后通过glTexCoord2f( ...

  4. FATAL ha.BootstrapStandby: Unable to fetch namespace information from active NN at ***

    This problem (Unable to fetch namespace information from active NN) occurs, because the active namen ...

  5. 推荐两篇Unity与Android交互的文章

    http://www.xuanyusong.com/archives/676 里面18,19介绍

  6. table合并单元格colspan和rowspan .

    colspan和rowspan这两个属性用于创建特殊的表格. colspan是“column span(跨列)”的缩写.colspan属性用在td标签中,用来指定单元格横向跨越的列数: 在浏览器中将显 ...

  7. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 创建复杂数据模型

    Creating a complex data model 创建复杂数据模型 8 of 9 people found this helpful The Contoso University sampl ...

  8. program testy data

    做项目得用数据吧,拿去.... 1.Data.gov搜索   美国政府去年承诺使所有政府数据都能在网上免费获得.这个网站是第一阶段,作为一个门户网站,囊括了从气候到犯罪的一切惊人的信息.   2. 美 ...

  9. 【CITE】C#入门学习-----简单画图程序

    版权声明:本文为博主原创文章,未经博主允许不得转载. 欢迎大家提出意见,一起讨论! 转载请标明是引用于 http://blog.csdn.net/chenyujing1234 通过本实例了解如何在窗体 ...

  10. sealed(C# 参考)

    sealed 修饰符可以应用于类.实例方法和属性.密封类不能被继承.密封方法会重写基类中的方法,但其本身不能在任何派生类中进一步重写.当应用于方法或属性时,sealed 修饰符必须始终与 overri ...