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
 

Code
 1 #include <stdio.h>
 2 #include <math.h>
 3 #define N 10000
 4 struct Point
 5 {
 6     double x;
 7     double y;
 8     double z;
 9 }points[N + 5];
10 int count;                    //everytime the number of points 
11 double a[N + 5], b[N + 5];    //array a is r, array b is h 
12 double getMaxH(double R)
13 {
14     double max, h;
15     int i;
16     max = 0;
17     for (i = 1; i <= count; i++)
18     {
19         h = R * b[i] / (R - a[i]);
20         if (h > max)
21             max = h;
22     }
23     return max;
24 }
25 double f(double r, double h)
26 {
27     return r * r * h;
28 }
29 void main()
30 {
31     int i, n;
32     double rlow, rhigh, rmid1, rmid2, max, h1, h2;
33     max = 0;
34     scanf("%d", &n);
35     while (n--)
36     {
37         scanf("%d", &count);
38         for (i = 1; i <= count; i++)
39         {
40             scanf("%lf %lf %lf", &points[i].x, &points[i].y, &points[i].z);
41             a[i] = sqrt (points[i].x * points[i].x + points[i].y * points[i].y);
42             b[i] = points[i].z;
43             if (a[i] > max)
44                 max = a[i];
45         }
46         rlow = max;
47         rhigh = 1e6;
48         while (rhigh - rlow >= 1e-6)
49         {
50             rmid1 = (rhigh + rlow) / 2;
51             rmid2 = (rhigh + rmid1) / 2;
52             h1 = getMaxH(rmid1);
53             h2 = getMaxH(rmid2);
54             if (f(rmid1, h1) < f(rmid2, h2))
55                 rhigh = rmid2;
56             else
57                 rlow = rmid1;
58         }
59         printf("%.3lf %.3lf\n", h1, rmid1);
60     }
61 }

 

 

Idea

To begin with, u should reduce the X-Y-Z to X-Z, by using r = sqrt(x * x + y * y)

Secondly, u should prove that when r increase, then v will reduce, then when r reduce, the v will reduce. Note, maybe u will get the value of the k, I try my best to use the value, but it's proved that it's no use.

Last, u can use the trichotomy to divide the R. Note, u should count all the point so that u can get the max h, which means u contain all the points.

Key point

Firstly, u should write down the whole codes on the paper so that u can save the time to debug.

 
posted on 2013-03-17 20:43  MrMission  阅读(252)  评论(0编辑  收藏  举报