hdoj3756Dome of Circus【三分法】

来源:互联网 发布:ctf flag.php 编辑:程序博客网 时间:2024/05/26 17:46



Dome of Circus

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1492    Accepted Submission(s): 629
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
311.00 0.00 1.0021.00 0.00 1.000.00 1.50 0.5031.00 0.00 1.000.00 1.50 0.50-0.50 -0.50 1.00
 

Sample Output
3.000 1.5002.000 2.0002.000 2.000
 

题意:给定三维空间中的点求一个最小的圆锥覆盖所有圆;

解题思路:先将三维坐标化为二维利用圆柱坐标之后利用三分法枚举底面半径求得最小半径

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#define PI 3.1415926#define eps 1e-8using namespace std;struct point{double x,y,z,rr;}A[10010];double MAX(double a,double b){return a>b?a:b;}double getH(double r,int n){//利用相似三角形求出高 double maxk=-1.0;for(int i=0;i<n;++i){double k=A[i].z/(r-A[i].rr);maxk=MAX(k,maxk);}return maxk*r;}int main(){int t,n,i,j,k;scanf("%d",&t);while(t--){scanf("%d",&n);double minr=0;for(i=0;i<n;++i){scanf("%lf%lf%lf",&A[i].x,&A[i].y,&A[i].z);A[i].rr=sqrt(A[i].x*A[i].x+A[i].y*A[i].y);minr=MAX(minr,A[i].rr);}double left=minr,right=10010,H,R;int size=50;while(size--){double mid=(left+right)/2.0;double mmid=(mid+right)/2.0;double h1=getH(mid,n);double h2=getH(mmid,n);if(h1*mid*mid<h2*mmid*mmid){right=mmid;R=mid;H=h1;}else {left=mid;R=mmid;H=h2;}}printf("%.3lf %.3lf\n",H,R); }return 0;} 


0 0
原创粉丝点击