POJ3384-Feng Shui

Feng Shui
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 4230 Accepted: 1294 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 ≤ 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 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
//AC代码
/*
题意:顺时针给你n个点地板,然后你用两个一样圆形地毯(半径为R)覆盖一个多边形地板,求这两个地毯最多能覆盖多边形的面积此时的两圆的圆心坐标
此题用半平面交将多边形的每条边一起向“内”推进R,得到新的多边形,然后求多边形的最远两点(这两点即是两圆圆心)
另外注意:此题要精确4位小数,所以程序计算的样例得出的结果和题目上的结果不一样
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>
const int INF=0x7fffffff;
const double eps=1e-8;
const double PI=acos(-1.0);
const double inf=1e5;
const int Max=2001;
#define zero(x) (((x)>0?(x):-(x))<eps)
#define mm(a,b) memset(a,b,sizeof(a))
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
    Node(const double &_x=0, const double &_y=0) : x(_x), y(_y) {}
    void input()
    {
        cin>>x>>y;
    }
    void output()
    {
        cout<<x<<" "<<y<<endl;
    }
}point;
point list[Max],stack[Max];
point qq[Max],pp[Max],pnt[Max];
int n;
int top;

int cnt;
int curcnt;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
bool cmp(point p1,point p2)
{
    double temp;
    temp=xmult(list[0],p1,p2);
    if(temp>0)
        return true;
    if(temp==0&&(Distance(list[0],p1)<Distance(list[0],p2)))
        return true;
    return false;
}
void Init(int n)
{
    int i;
    for(i=1;i<=n;i++)
    {
        pp[i]=pnt[i];
    }
    pp[n+1]=pnt[1];
    pp[0]=pnt[n];
    cnt=n;
}
void GetLine(point u,point v,double &a,double &b,double &c)
{
    a=v.y-u.y;
    b=u.x-v.x;
    c=v.x*u.y-u.x*v.y;
}
point Intersect(point u,point v,double a,double b,double c)
{
    double q=fabs(a*u.x+b*u.y+c);
    double p=fabs(a*v.x+b*v.y+c);
    point res;
    res.x=((p*u.x+q*v.x)/(q+p));
    res.y=((p*u.y+q*v.y)/(q+p));
    return res;
}
void CutLine(double a,double b,double c)
{
    int i;
    curcnt=0;
    for(i=1;i<=cnt;i++)
    {
        if(sign(a*pp[i].x+b*pp[i].y+c)>=0)
        {
            qq[++curcnt]=pp[i];
        }
        else
        {
            if(sign(a*pp[i-1].x+b*pp[i-1].y+c)>0)
            {
                qq[++curcnt]=Intersect(pp[i],pp[i-1],a,b,c);
            }
            if(sign(a*pp[i+1].x+b*pp[i+1].y+c)>0)
            {
                qq[++curcnt]=Intersect(pp[i],pp[i+1],a,b,c);
            }
        }
    }
    for(i=1;i<=curcnt;i++)
    {
        pp[i]=qq[i];
    }
    pp[curcnt+1]=pp[1];
    pp[0]=pp[curcnt];
    cnt=curcnt;
}
bool solve(double r)//多边形每条边向内推进r距离得到新的多边形
{
    Init(n);
    int i;
    double kk,a,b,c;
    point ta,tb,tt;
    for(i=1;i<=n;i++)
    {
        tt.x=pnt[i+1].y-pnt[i].y;
        tt.y=pnt[i].x-pnt[i+1].x;
        kk=r/sqrt(tt.x*tt.x+tt.y*tt.y);
        tt.x=tt.x*kk;
        tt.y=tt.y*kk;
        ta.x=pnt[i].x+tt.x;
        ta.y=pnt[i].y+tt.y;
        tb.x=pnt[i+1].x+tt.x;
        tb.y=pnt[i+1].y+tt.y;
        GetLine(ta,tb,a,b,c);
        CutLine(a,b,c);
    }
    if(cnt<=0)
        return false;
    return true;
}
int main()
{
    int m,i,j;
    int ra,rb;
    double r;
    double maxn,temp;
    while(cin>>n>>r)
    {
        for(i=1;i<=n;i++)
            pnt[i].input();
        pnt[n+1]=pnt[1];
        //Init(n);
        solve(r);
        ra=0;
        rb=0;
        maxn=-99999;
        for(i=1;i<=cnt;i++)
        {
            for(j=i+1;j<=cnt;j++)
            {
                temp=Distance(pp[i],pp[j]);
                if(temp>maxn)
                {
                    maxn=temp;
                    ra=i;
                    rb=j;
                }
            }
        }
        cout<<setprecision(4)<<setiosflags(ios::fixed)<<pp[ra].x<<" "<<pp[ra].y<<" "<<pp[rb].x<<" "<<pp[rb].y<<endl;
    }
    return 0;
}
/*
5 2
-2 0
-5 3
0 8
7 3
5 0

4 3
0 0
0 8
10 8
10 0


*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值