# Uvalive 4986 (search by three points)

Source: Internet
Author: User

Uvalive 4986 (search by three points)

There are n vertices in the space. Find a minimum volume cone and pack all vertices. The height and bottom radius of the output cone. The center of the bottom of the cone is (0, 0), and The zcoordinate of all points is greater than or equal to 0.
Problem: Because the cone volume is V = 1/3 * π * r ^ 2 * h, this is a quadratic function, that is, a convex function. You can use a three-point search method to enumerate two heights, find the corresponding minimum r, and compare the two high values to continue the three-point search.

``````# Include

# Include

# Include

Using namespace std; const double PI = acos (-1); const double eps = 1e-9; struct Point {double x, y; Point (double a = 0, double B = 0): x (a), y (B) {}}; typedef Point Vector; double dcmp (double x) {if (fabs (x) <eps) return 0; return x <0? -1: 1;} Vector operator + (const Point & A, const Point & B) {return Vector (. x + B. x,. y + B. y);} Vector operator-(const Point & A, const Point & B) {return Vector (. x-B. x,. y-B. y);} Vector operator * (const Point & A, double a) {return Vector (. x * a,. y * a);} Vector operator/(const Point & A, double a) {return Vector (. x/a,. y/a);} double Cross (const Vector & A, const Vector & B) {return. x * B. y-. y * B. x;} double Dot (const Vector & A, const Vector & B) {return. x * B. x +. y * B. y;} double Length (const Vector & A) {return sqrt (Dot (A, A);} bool operator <(const Point & A, const Point & B) {return. x <B. x | (. x = B. x &. y <B. y);} bool operator = (const Point & A, const Point & B) {return. x = B. x &. y = B. y;} const int N = 10005; Point P [N], HP [N]; int n; double solve (double h) {double r =-1; // (P [I]. x-0, P [I]. y-h) (r-0, 0-h) Coaxial for (int I = 0; I <n; I ++) if (P [I]. x * h/(h-P [I]. y)> r) r = P [I]. x * h/(h-P [I]. y); return r;} int main () {while (scanf (% d, & n) = 1) {double x, y, z, l = 0, r = 1e9; for (int I = 0; I <n; I ++) {scanf (% lf, & x, & y, & z ); double d = sqrt (x * x + y * y); P [I]. x = d; P [I]. y = z; l = max (l, z);} while (dcmp (r-l)> 0) {double h1 = (l + r)/2; double h2 = (h1 + r)/2; double r1 = solve (h1); double r2 = solve (h2 ); if (r1 * r1 * h1 <r2 * r2 * h2) r = h2; else l = h1;} printf (%. 3lf %. 3lf, l, solve (l);} return 0 ;}

``````

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.