hdu 3756 Dome of Circus(模拟退火)

Dome of Circus

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 922    Accepted Submission(s): 411
Special Judge


Problem Description
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 ≤ i ≤ 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.
 

Input
The input begins with an integer T. The next T blocks each represents a case. The first line of each case contains a single integer number n (1 ≤ n ≤ 10 000) - 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 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
  
  
3 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
 

Author
Georgiy Korneev
 

Source
 

Recommend
notonlysuccess


题意:求包含所有点的圆锥的高和底半径

题解:模拟退火...水过....应该是一道三分题目


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define eps 1e-8
#define luck 8
#define all 2
#define pi acos(-1.0)
struct point{
    double x,y;
}p[10005],tp[18],now,temp;
int n;
double V(double r,double h){return 1.0/3*pi*r*r*h;}
double MAX(double a,double b){ return a>b?a:b; }
double get_h(double mid)
{
    double temp,res=0;
    int i;
    for(i=0;i<n;i++)
    {
        temp=p[i].y*mid/(mid-p[i].x);
        if(temp>res) res=temp;
    }
    return res;
}
int main()
{
    int t,i,j,id;
    double x,y,z,best[18];
    double low,res,tmp,step;
    //freopen("t","r",stdin);
    srand((unsigned)time(NULL));
    scanf("%d",&t);
    while(t--)
    {
        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;
            low=MAX(p[i].x,low);
        }
        for(i=0;i<all;i++)
        {
            tp[i].x=(rand()%1000+1)/1000.0*3*low+low;
            tp[i].y=get_h(tp[i].x);
            //printf("%lf\n",tp[i].y);
            best[i]=V(tp[i].x,tp[i].y);
        }
        step=low;
        while(step>1e-4)
        {
            for(i=0;i<all;i++)
            {
                now=tp[i];
                for(j=0;j<luck;j++)
                {
                    temp.x=now.x+(rand()%1000-499)/1000.0*step;
                    if(temp.x<low+eps) continue;
                    temp.y=get_h(temp.x);
                    tmp=V(temp.x,temp.y);
                    if(tmp<best[i])
                    {
                        best[i]=tmp;
                        tp[i]=temp;
                    }
                }
            }
            step=step*0.6;
        }
        res=999999999.0;
        for(i=0;i<all;i++)
        {
            if(best[i]<res)
            {
                res=best[i];
                id=i;
            }
        }
        printf("%.3lf %.3lf\n",tp[id].y,tp[id].x);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值