# poj 3384 Feng Shui （半平面交）

Feng Shui
 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5519 Accepted: 1656 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

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

Sample Output

#1 -2 3 3 2.5 3 5 7 3

Hint

Source

Northeastern Europe 2006, Northern Subregion

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 1003
#define eps 1e-12
#define inf 1e9
using namespace std;
struct vector {
double x,y;
vector (double X=0,double Y=0){
x=X,y=Y;
}
}a[N],tmp[N],p[N];
struct data{
vector a,b;
}line[N];
int n,m;
double r,pi=acos(-1.0);
typedef vector point;
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 t){
return vector (a.x*t,a.y*t);
}
vector operator /(vector a,double t){
return vector (a.x/t,a.y/t);
}
int dcmp(double x)
{
if (fabs(x)<eps) return 0;
return x<0?-1:1;
}
double cross(vector a,vector b)
{
return a.x*b.y-a.y*b.x;
}
{
}
double len(vector a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
void init()
{
m=0;
p[m++]=point(inf,inf);
p[m++]=point(-inf,inf);
p[m++]=point(-inf,-inf);
p[m++]=point(inf,-inf);
}
point glt(point a,point a1,point b,point b1)
{
vector v=a1-a; vector w=b1-b;
vector u=a-b;
double t=cross(w,u)/cross(v,w);
return a+v*t;
}
void cut(point a,point b)
{
int cnt=0;
memset(tmp,0,sizeof(tmp));
for (int i=0;i<m;i++){
double c=cross(b-a,p[i]-a);
double d=cross(b-a,p[(i+1)%m]-a);
if (dcmp(c)<=0) tmp[cnt++]=p[i];
if (dcmp(c)*dcmp(d)<0)
tmp[cnt++]=glt(a,b,p[i],p[(i+1)%m]);
}
m=cnt;
for (int i=0;i<cnt;i++) p[i]=tmp[i];
}
int main()
{
freopen("a.in","r",stdin);
scanf("%d%lf",&n,&r);
for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
a[n+1]=a[1];
for (int i=2;i<=n+1;i++){
vector v=a[i]-a[i-1];
vector u=rotate(v,3*pi/2)/len(v);
u=u*r;
line[i-1].a=a[i-1]+u;
line[i-1].b=line[i-1].a+v;
//cout<<line[i-1].a.x<<" "<<line[i-1].a.y<<endl;
//cout<<line[i-1].b.x<<" "<<line[i-1].b.y<<endl;
}
init();
for (int i=1;i<=n;i++) cut(line[i].a,line[i].b);
point ans,ansx; double mx=0;
for (int i=0;i<m-1;i++)
for (int j=i+1;j<m;j++){
double t=len(p[i]-p[j]);
if (t>mx) {
mx=t;
ans=p[i]; ansx=p[j];
}
}
if (m==1) ans=p[0],ansx=p[0];
printf("%.4lf %.4lf %.4lf %.4lf\n",ans.x,ans.y,ansx.x,ansx.y);
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：poj 3384 Feng Shui （半平面交） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)