poj 3384 Feng Shui (半平面交)

原创 2017年01月03日 19:42:42

Feng Shui
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 5519   Accepted: 1656   Special Judge


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.


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.


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



Northeastern Europe 2006, Northern Subregion

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




#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){
struct data{
	vector a,b;
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()
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;
	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) 
	for (int i=0;i<cnt;i++) p[i]=tmp[i];
int main()
		for (int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
		for (int i=2;i<=n+1;i++){
			vector v=a[i]-a[i-1];
			vector u=rotate(v,3*pi/2)/len(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;
		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) {
		 		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);

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/clover_hxy/article/details/53997319

POJ3384Feng Shui【半平面交】

Language: Default Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Subm...
  • R1986799047
  • R1986799047
  • 2015年09月15日 15:41
  • 543

POJ 3384 Feng Shui(半平面交)

转载请注明出处,谢谢http://blog.csdn.net/acm_cxlove/article/details/7854526       by---cxlove 题目:给出一个凸多边形的房...
  • ACM_cxlove
  • ACM_cxlove
  • 2012年08月19日 14:33
  • 1972

POJ3384-Feng Shui

Feng Shui Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4230   Acce...
  • u010296826
  • u010296826
  • 2014年07月27日 15:07
  • 421

[POJ3384]Feng Shui(半平面交)

题目描述传送门题解首先如果想要把圆放进去,每条边往里平移r了之后一定存在至少一个凸壳 凸壳上的点就是圆心的可行解 要求圆心距最大,就是找凸壳上距离最远的点 这两个点一定在凸壳的顶点处,暴力枚举就...
  • Clove_unique
  • Clove_unique
  • 2017年01月04日 11:04
  • 426

POJ 3384 Feng Shui

坑爹的题,,就是先向内推进r,然后半平面交得出圆心范围。 然后旋转卡壳求最远点对 这道题首先样例给的就不对,不知道什么情况 然后一直WA,后来看了discuss,试了下这组数据: 4 1 0...
  • lj94093
  • lj94093
  • 2015年01月25日 19:05
  • 279

poj 3384

题目概述按顺时针序给定一个简单凸N边形的所有顶点坐标x,y,以及圆的半径R,将两个如此的圆放在多边形中,求圆心的坐标,使得两圆覆盖多边形的面积最大 圆只能与多边形相切,但两个圆可以相交,数据确保多边...
  • liurui39660
  • liurui39660
  • 2016年07月30日 17:27
  • 331

POJ 3384 Feng Shui 半平面交

题目给出两个圆和一个多边形 问是否能让两个圆在多边形内。 并且覆盖的面积最大 圆的半径为r,我们则让多边形的每条边都往内部退r距离。 然后求半平面交得出的点集中,最远的两个点则是两圆的...
  • sdj222555
  • sdj222555
  • 2013年11月01日 12:59
  • 1043

poj 3384 Feng Shui(半平面交)

用两个圆去覆盖多边形,问最多能覆盖多少面积,输出最终两个圆的圆心坐标。 把多边形的各边向内推进r距离,因为题目保证输入合法,则推进后必定能形成一个多边形,只要找这个多边形的距离最远的两个点就行了。 ...
  • crazy852456
  • crazy852456
  • 2013年09月03日 15:58
  • 466

POJ 3384 Feng Shui(半平面交)

  • u013112097
  • u013112097
  • 2014年06月30日 21:45
  • 279

[半平面交] poj 3384 Feng Shui

#include #include #include #include const double eps = 1e-8; inline double delt(double a) { ...
  • NOI2015
  • NOI2015
  • 2015年02月27日 21:57
  • 284
您举报文章:poj 3384 Feng Shui (半平面交)