关闭

poj 3384 Feng Shui (半平面交)

56人阅读 评论(0) 收藏 举报
分类:

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

#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

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


题目大意:再凸多边形内放两个半径r的圆,求如果放置是覆盖的面积最大。

题解:半平面交。

将边界向内缩R,然后求凸包的最远点对。

#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;
}
point rotate(vector a,double rad)
{
	return point(a.x*cos(rad)-a.y*sin(rad),a.y*cos(rad)+a.x*sin(rad));
}
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);
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:233061次
    • 积分:14495
    • 等级:
    • 排名:第823名
    • 原创:1275篇
    • 转载:12篇
    • 译文:0篇
    • 评论:67条
    欢迎交流
    QQ:1184204539
    最新评论