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

 
   
#1 5 2 -2 0 -5 3 0 8 7 3 5 0
#2 4 3 0 0 0 8 10 8 10 0

Sample Output

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

Hint

POJ3384-Feng Shui_第1张图片

Source

Northeastern Europe 2006, Northern Subregion
//AC代码
/*
题意:顺时针给你n个点地板,然后你用两个一样圆形地毯(半径为R)覆盖一个多边形地板,求这两个地毯最多能覆盖多边形的面积此时的两圆的圆心坐标
此题用半平面交将多边形的每条边一起向“内”推进R,得到新的多边形,然后求多边形的最远两点(这两点即是两圆圆心)
另外注意:此题要精确4位小数,所以程序计算的样例得出的结果和题目上的结果不一样
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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)-(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<0)
        return true;
    if(temp==0&&(Distance(list[0],p1)=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<

你可能感兴趣的:(半平面交)