Dome of Circus - UVa 1473 几何 凸包

39 篇文章 0 订阅

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; (xiyizi) 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 zcoordinates 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 xiyi, 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

题意:让你构造体积最小的圆锥,使得其包含给定的所有点。

思路:首先每个点都可以旋转后转化到二维平面上,然后由第一组样例可知r=1.5x,h=3y时体积最小。先求凸包,然后根据凸包上相邻两点的斜率,找最接近这个直线的情况。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct Point
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
    Point operator - (const Point P) const{return Point(x-P.x,y-P.y);}
    bool operator<(const Point P) const
    {
        if(x==P.x)
          return y<P.y;
        return x<P.x;
    }
};
double Cross(Point A,Point B){return A.x*B.y-A.y*B.x;}
double getx(Point A,Point B){return (A.x*B.y-B.x*A.y)/(B.y-A.y);}
double gety(Point A,Point B){return (A.x*B.y-B.x*A.y)/(A.x-B.x);}
int n,m,k;
Point p[10010],ch[10010];
double a[10010];
void ConvexHull()
{
    int i,j;
    m=0;
    sort(p,p+n);
    for(i=0;i<n;i++)
    {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
          m--;
       ch[m++]=p[i];
    }
    k=m;
    for(i=n-2;i>=0;i--)
    {
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
            m--;
        ch[m++]=p[i];
    }
    if(n>1)
      m--;
    ch[m]=ch[0];
}
int main()
{
    int i,j;
    double x,y,z,minn,r,h,R,H;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf%lf",&x,&y,&z);
            p[i].x=sqrt(x*x+y*y);
            p[i].y=z;
        }
        ConvexHull();
        minn=1e18;
        a[k-1]=ch[k-1].x;
        for(i=k;i<=m;i++)
        {
            if(ch[i].y<=ch[i-1].y)
              break;
            a[i]=getx(ch[i],ch[i-1]);
            if(1.5*ch[i-1].x<a[i-1])
              r=a[i-1],h=gety(ch[i-1],Point(r,0));
            else if(1.5*ch[i-1].x<a[i])
              r=1.5*ch[i-1].x,h=3*ch[i-1].y;
            else
              r=a[i],h=h=gety(ch[i-1],Point(r,0));
            if(r*r*h<minn)
            {
                R=r;H=h;
                minn=r*r*h;
            }
        }
        if(1.5*ch[i-1].x<a[i-1])
          r=a[i-1],h=gety(ch[i-1],Point(r,0));
        else
          r=1.5*ch[i-1].x,h=3*ch[i-1].y;
        if(r*r*h<minn)
        {
            R=r;H=h;
            minn=r*r*h;
        }
        printf("%.3f %.3f\n",H,R);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值