UVA1473 - Dome of Circus

做了两天……终于搞定了


就是给你一些点,求能够包裹这些点体积最小的圆锥的底圆半径和圆锥的高


虽然网上很多用三分的方法写,不过好像是某电的课件做法,然后很多人跟风……


不管怎么说,我是用计算几何的方法写的


我的做法:


观察之后可以发现把一个点投影到xoy平面上跟原点的距离可以当作x对待,原来的z可以当作y对待,这样就转换成了二维


只需要在二维图中找一条线与x,y轴围住这些点就行了


想一想就会发现,这条线肯定经过一个点或者两个点,因为圆锥体相当于这条线围绕y轴旋转一周后形成


两个点能够唯一确定一条直线,那么一个点也可以确定一个体积最小的圆锥体,通过列表达式求导可以知道,r=1.5x,h=3y的时候满足


找一个右极点逆时针做凸包,逆时针爬到最高处即可遍历可能的情况


我的代码:


#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
struct ddot
{
	double x,y;
	ddot(){};
	ddot(double a,double b)
	{
		x=a;
		y=b;
	}
};
ddot operator -(ddot a,ddot b)
{
	return ddot(a.x-b.x,a.y-b.y);
}
double operator *(ddot a,ddot b)
{
	return a.x*b.y-b.x*a.y;
}
bool cmp(ddot a,ddot b)
{
	return a.x!=b.x?a.x>b.x:a.y>b.y;
}
ddot K;
double dis2(ddot a,ddot b)
{
	return pow(a.x-b.x,2)+pow(a.y-b.y,2);
}
bool cmp1(ddot a,ddot b)
{
	double t=(a-K)*(b-K);
	return t!=0?t>0:dis2(a,K)>dis2(b,K);
}
double ch(ddot a,ddot b)
{
	return (b.y*a.x-b.x*a.y)/(a.x-b.x);
	
}
double cr(ddot a,ddot b)
{
	return (b.y*a.x-b.x*a.y)/(b.y-a.y);
}
int main()
{
	int i,top,n,ymax;
	double x,y,z,h,r,t,low,high,vmin,hmin,rmin;
	ddot dot[10010],box[10010];
	while(cin>>n)
	{
		for(i=0;i<n;i++)
		{
			scanf("%lf%lf%lf",&x,&y,&z);
			dot[i].x=sqrt(x*x+y*y);
			dot[i].y=z;
		}
		sort(dot,dot+n,cmp);
		K=dot[0];
		sort(dot+1,dot+n,cmp1);
		box[0]=dot[0];box[1]=dot[1];
		top=1;
		for(i=2;i<n;)
		{
			t=(box[top]-box[top-1])*(dot[i]-box[top-1]);
			if(t>0)
				box[++top]=dot[i++];
			else if(t==0)
				i++;
			else
				top--;
		}
		ymax=0;
		for(i=0;i<=top;i++)
			if(box[i].y>box[ymax].y)
				ymax=i;
		vmin=1e99;
		for(i=0;i<=ymax;i++)
		{
			if(i==0)
				low=box[0].x;
			else
				low=cr(box[i],box[i-1]);
			if(i==ymax)
				high=1e99;
			else
				high=cr(box[i],box[i+1]);
			t=1.5*box[i].x;
			if(t<low)
			{
				r=low;
				h=ch(box[i],box[i-1]);
			}
			else if(t<=high)
			{
				r=t;
				h=box[i].y*3;
			}
			else
			{
				r=high;
				h=ch(box[i],box[i+1]);
			}
			t=r*r*h;
			if(t<vmin)
			{
				vmin=t;
				rmin=r;
				hmin=h;
			}
		}
		printf("%.3lf %.3lf\n",hmin,rmin);
	}
}

Time limit: 3.000 seconds

A travelling circus faces a tough challenge in designing the dome for its performances. The circus has a number of shows that happen above the stage in the air under the dome. Various rigs, supports, and anchors must be installed over the stage, but under the dome. The dome itself must rise above the center of the stage and has a conical shape. The space under the dome must be air-conditioned, so the goal is to design the dome that contains minimal volume.

You are given a set of n points in the space; (xi, yi, zi) for 1$ \le$i$ \le$n are the coordinates of the points in the air above the stage that must be covered by the dome. The ground is denoted by the plane z = 0, with positive z coordinates going up. The center of the stage is on the ground at the point (0, 0, 0).

The tip of the dome must be located at some point with coordinates (0, 0, h) with h > 0. The dome must have a conical shape that touches the ground at the circle with the center in the point (0, 0, 0) and with the radius of r. The dome must contain or touch all the n given points. The dome must have the minimal volume, given the above constraints.

\epsfbox{p4986.eps}

Input 

The input file contains several test cases, each of them as described below.

The first line of the input file contains a single integer number n (1$ \le$n$ \le$10000) -- the number of points under the dome. The following n lines describe points with three floating point numbers xi, yi, and zi per line -- the coordinates of i-th point. All coordinates do not exceed 1000 by their absolute value and have at most 2 digits after decimal point. All zi are positive. There is at least one point with non-zero xi or yi.

Output 

For each test case, write to the output file a single line with two floating point numbers h and r -- the height and the base radius of the dome. The numbers must be precise up to 3 digits after decimal point.

Sample Input 

1 
1.00 0.00 1.00 
2 
1.00 0.00 1.00 
0.00 1.50 0.50 
3 
1.00 0.00 1.00 
0.00 1.50 0.50 
-0.50 -0.50 1.00

Sample Output 

3.000 1.500 
2.000 2.000 
2.000 2.000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值