hdu3756三分基础题

Dome of Circus

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 937    Accepted Submission(s): 420 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
 

一道几何三分题,其实三分和二分差不多,懂三分算法就挺简单的

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 #include <math.h>
 6 #include <vector>
 7 #include <stack>
 8 using namespace std;
 9 #define ll long long int
10 #define INF 0.0001
11 #define PII  3.1415926535898
12 int m;
13 double a[20000][3];
14 double fun(double x)
15 {
16     int i;
17     double r=(x*sqrt(a[0][0]*a[0][0]+a[0][1]*a[0][1]))/(x-a[0][2]);
18     for(i=1;i<m;i++)
19     {
20         if(r<(x*sqrt(a[i][0]*a[i][0]+a[i][1]*a[i][1]))/(x-a[i][2]))
21         r=(x*sqrt(a[i][0]*a[i][0]+a[i][1]*a[i][1]))/(x-a[i][2]);
22     }
23     return r;
24 }
25 int main()
26 {
27         cin>>m;
28         int j;
29         double low=-99999;
30         for(j=0;j<m;j++)
31         {
32             cin>>a[j][0]>>a[j][1]>>a[j][2];
33             if(low<a[j][2])
34             low=a[j][2];
35         }
36         double hight=20000.0;
37         double x,y,rx,ry;
38         while(hight-low>INF)
39         {
40 
41             x=(hight-low)/3+low;
42             y=low+2*(hight-low)/3;
43              rx=fun(x);
44              ry=fun(y);
45             if(PII*rx*rx*x/3>PII*ry*ry*y/3)
46             {
47                 low=x;
48             }
49             else
50             {
51                 hight=y;
52             }
53         }
54         printf("%.3lf %.3lf
",hight,ry);
55     return 0;
56 }
View Code
原文地址:https://www.cnblogs.com/ERKE/p/3256417.html