poj 3384 Feng Shui(内推进半平面交+最远点对)

Feng Shui
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 3964 Accepted: 1218 Special Judge

Description

Feng shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George has recently got interested in it, and now wants to apply it to his home and bring harmony to it.

There is a practice which says that bare floor is bad for living area since spiritual energy drains through it, so George purchased two similar round-shaped carpets (feng shui says that straight lines and sharp corners must be avoided). Unfortunately, he is unable to cover the floor entirely since the room has shape of a convex polygon. But he still wants to minimize the uncovered area by selecting the best placing for his carpets, and asks you to help.

You need to place two carpets in the room so that the total area covered by both carpets is maximal possible. The carpets may overlap, but they may not be cut or folded (including cutting or folding along the floor border) — feng shui tells to avoid straight lines.

Input

The first line of the input file contains two integer numbers n and r — the number of corners in George’s room (3 ≤ n ≤ 100) and the radius of the carpets (1 ≤ r ≤ 1000, both carpets have the same radius). The following n lines contain two integers xi and yi each — coordinates of the i-th corner (−1000 ≤ xiyi ≤ 1000). Coordinates of all corners are different, and adjacent walls of the room are not collinear. The corners are listed in clockwise order.

Output

Write four numbers x1y1x2y2 to the output file, where (x1y1) and (x2y2) denote the spots where carpet centers should be placed. Coordinates must be precise up to 4 digits after the decimal point.

If there are multiple optimal placements available, return any of them. The input data guarantees that at least one solution exists.

Sample Input

 
 
#15 2 -2 0 -5 3 0 8 7 3 5 0
#24 3 0 0 0 8 10 8 10 0

Sample Output

 
 
#1-2 3 3 2.5
#23 5 7 3

Hint

Source

Northeastern Europe 2006, Northern Subregion

题意:顺时针给定一个凸多边形,问放入2个半径为r的圆,并且圆要完全在多边形内,问2个圆所覆盖的面积最大的时候,2个点的位置,若有多种情况,任意输出一种

题解:将所有边内推进r求半平面交,然后求得出的凸多边形的最远点对就是一组解,最远点对不用卡壳旋转也行,数据很小


#include<stdio.h>
#include<math.h>
#define N 208
#define eps 1e-9
struct point{
    double x,y;
}p[N],temp[N],tp[N];
double a1,b1,c1,res;
double dis(struct point p1,struct point p2)
{
    return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
void move_get_line(struct point p1,struct point p2,double r)
{
    double tmd;

    temp[203].x=p2.y-p1.y;
    temp[203].y=p1.x-p2.x;
    tmd=sqrt(temp[203].x*temp[203].x+temp[203].y*temp[203].y);
    temp[203].x=temp[203].x/tmd*r;
    temp[203].y=temp[203].y/tmd*r;
    p1.x+=temp[203].x;
    p1.y+=temp[203].y;
    p2.x+=temp[203].x;
    p2.y+=temp[203].y;
    a1=p1.y-p2.y;
    b1=p2.x-p1.x;
    c1=p1.x*p2.y-p1.y*p2.x;
}
void get_interest(struct point p1,struct point p2)
{
    double a2=p1.y-p2.y;
    double b2=p2.x-p1.x;
    double c2=p1.x*p2.y-p1.y*p2.x;
    double tmd=a1*b2-a2*b1;
    temp[203].x=(b1*c2-b2*c1)/tmd;
    temp[203].y=(a2*c1-a1*c2)/tmd;
}
int cut(int m)
{
    int i,top=0;

    for(i=1;i<=m;i++)
    {
        if(a1*temp[i].x+b1*temp[i].y+c1<=eps) tp[++top]=temp[i];
        else
        {
            if(a1*temp[i-1].x+b1*temp[i-1].y+c1<-eps)
            {
                get_interest(temp[i],temp[i-1]);
                tp[++top]=temp[203];
            }
            if(a1*temp[i+1].x+b1*temp[i+1].y+c1<-eps)
            {
                get_interest(temp[i],temp[i+1]);
                tp[++top]=temp[203];
            }
        }
    }
    tp[0]=tp[top],tp[top+1]=tp[1];
    for(i=0;i<=top+1;i++) temp[i]=tp[i];

    return top;
}
int half_plane(int n,double r)
{
    int i,m=n;

    for(i=0;i<=n+1;i++) temp[i]=p[i];
    for(i=1;i<=n;i++)
    {
        move_get_line(p[i],p[i+1],r);
        m=cut(m);
    }

    return m;
}

void get_farthest(int n)
{
    double res=0,tmd;
    int i,j;

    for(i=1,j=1;i<=n;)
    {
        if(dis(temp[i],temp[j])<dis(temp[i],temp[j+1])) j=(j+1)%n;
        else
        {
            tmd=dis(temp[i],temp[j]);
            if(tmd>=res)
            {
                res=tmd;
                tp[205]=temp[i];
                tp[206]=temp[j];
            }
            i++;
        }
    }
}
int main()
{
    double r;
    int i,n;

    //freopen("t.txt","r",stdin);
    while(scanf("%d%lf",&n,&r)>0)
    {
        for(i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        p[0]=p[n],p[n+1]=p[1];
        n=half_plane(n,r);
        get_farthest(n);
        printf("%.4lf %.4lf ",tp[205].x,tp[205].y);
        printf("%.4lf %.4lf\n",tp[206].x,tp[206].y);
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值