poj3384Feng Shui

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 ≤ xi, yi ≤ 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 x1, y1, x2, y2 to the output file, where (x1, y1) and (x2, y2) 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 Input1
5 2
-2 0
-5 3
0 8
7 3
5 0

Sample Input2
4 3
0 0
0 8
10 8
10 0

Sample Output1
-2 3 3 2.5

Sample Output2
3 5 7 3

分析:
类似poj3525的思路
我们把每一条直线向内(向直线的右侧)平移r个单位,
那么两个圆的圆心必定在这个新凸多边形中,否则就会和原来的凸多边形的某条边相交
我们要最大化面积,
显然两个圆的圆心要相聚尽可能的远
所以查找一下新的凸多边形中距离最远的两个点即可
(有special judge)

这里写代码片
#include<cstdio>  //顺时针
#include<cstring>
#include<iostream>
#include<cmath>

using namespace std;

const int N=100001;
const double eps=1e-8;
struct node{
    double x,y;
    node (double xx=0,double yy=0)
    {
        x=xx;y=yy;
    }
};
node po[N],p[N],q[N];
int n,m;
double a,b,c,r,PI=acos(-1.0);

node operator +(const node &a,const node &b)
{
    return node(a.x+b.x,a.y+b.y);
}

node operator -(const node &a,const node &b)
{
    return node(a.x-b.x,a.y-b.y);
}

node operator *(const node &a,const double &b)
{
    return node(a.x*b,a.y*b);
}

node operator /(const node &a,const double &b)
{
    return node(a.x/b,a.y/b);
}

int dcmp(double x)
{
    if (fabs(x)<eps) return 0;
    else if (x>0) return 1;
    else return -1;
}

double Cross(node x,node y)
{
    return x.x*y.y-x.y*y.x;
}

double Dot(node x,node y)
{
    return x.x*y.x+x.y*y.y;
}

double dis(node x,node y)
{
    return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}

void getline(node x,node y)
{
    a=y.y-x.y;
    b=x.x-y.x;
    c=x.y*y.x-x.x*y.y;
}

node insert(node x,node y)
{
    double u=a*x.x+b*x.y+c;
    double v=a*y.x+b*y.y+c;
    node ans;
    ans.x=(v*x.x+u*y.x)/(u+v);
    ans.y=(v*y.x+u*y.y)/(u+v);
    return ans;
}

void cut()
{
    int i,cnt=0;
    for (i=1;i<=m;i++)
    {
        if (a*p[i].x+b*p[i].y+c>=0) q[++cnt]=p[i];
        else
        {
            if (a*p[i-1].x+b*p[i-1].y+c>0) q[++cnt]=insert(p[i],p[i-1]);
            if (a*p[i+1].x+b*p[i+1].y+c>0) q[++cnt]=insert(p[i],p[i+1]);
        } 
    }
    for (i=1;i<=m;i++) p[i]=q[i];
    p[0]=p[m]; p[m+1]=p[1];
    m=cnt;
    return;
}

void pd()
{
    int i,j;
    double ans=0;
    node a,b;
    for (i=1;i<m;i++)
    {
        for (j=i+1;j<=m;j++)
        {
            double t=dis(p[i],p[j]);
            if (t>ans)
            {
                ans=t;
                a=p[i];
                b=p[j];
            }
        }
    }
    printf("%0.4lf %0.4lf %0.4lf %0.4lf",a.x,a.y,b.x,b.y);
    return;
}

void doit()
{
    int i;
    for (i=1;i<=n;i++) p[i]=po[i];
    p[0]=p[n]; p[n+1]=p[1];
    po[0]=po[n]; po[n+1]=po[1];
    m=n;
    for (i=1;i<=n;i++)
    {
        getline(po[i],po[i+1]);
        c-=r*(sqrt(a*a+b*b));  //顺时针给点,直线向内平移 
        cut();
        if (!m) break;
    }
    pd(); 
}

int main()
{
    scanf("%d%d",&n,&r);
    for (int i=1;i<=n;i++)
        scanf("%lf%lf",&po[i].x,&po[i].y);
    doit();
    return 0;
}

转载于:https://www.cnblogs.com/wutongtong3117/p/7673497.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值