ACM learning process -- hdu5017 ellipsoid (Simulated Annealing) (2014 Xi 'an online competition K questions)

Source: Internet
Author: User

--- Restore content start ---

Description

Given a 3-dimension ellipsoid (elliptical)

Your task is to find the minimal distance between the original point (0, 0) and points on the ellipsoid. the distance between two points (x 1, Y 1, Z 1) and (x 2, Y 2, Z 2) is defined

Input

There are multiple test cases. Please process till EOF.

For each testcase, one line contains 6 real number A, B, C (0 <A, B, C, <1), d, e, f (0 ≤ D, E, F <1), As described abve. It is guaranteed that the input data forms a ellipsoid.All numbers are fit in double.

Output

For each test contains one line. describes the minimal distance. answer will be considered as correct if their absolute error is less than 10-5.

Sample Input

1 0.04 0.01 0 0 0

Sample output

1.0000000 this question can be simulated and annealed. You can search in eight directions at a certain point. If the distance decreases, you will naturally step in that direction, however, the step size must decrease with the number of times. When the step size reaches ESP, the natural precision meets the requirements. However, it should be noted that the Z root does not exist and the distance between the two roots is the smallest. After several tests, the decreasing coefficient of step is 0.97 to 0.99. Code:
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cmath> # define ESP 1e-7using namespace STD; bool flag; Double A, B, C, D, e, F; double Getz (Double X, Double Y) {double A = C; Double B = D * Y + E * X; double C = f * x * Y + A * x + B * y * Y-1.0; Double V = B * B-4 * a * C; if (v <0) {flag = 0; return 0;} flag = 1; V = SQRT (V); double z1 = (V-B)/A/2.0; double Z2 = (-v-B)/A/2.0; If (FABS (z1) <FABS (Z2) return Z1; else return Z2;} double DIS (Double X, Double Y) {Double Z = Getz (x, y ); if (flag = 0) return 0; return SQRT (x * x + y * Y + z * z);} double QT () // simulated annealing {Double X = 0, y = 0, min = DIS (x, y); double XX, YY, Len; double step = 1; while (Step> = ESP) {for (INT dx =-1; DX <= 1; ++ dx) {for (int dy =-1; dy <= 1; + + dy) {If (dx = 0 & DY = 0) continue; xx = x + step * DX; YY = Y + st EP * dy; Len = DIS (XX, YY); If (flag & Len <min) {min = Len; X = xx; y = YY ;}}} step * = 0.97;} return min;} int main () {// freopen ("test.txt", "r", stdin ); while (scanf ("% lf", & A, & B, & C, & D, & E, & F )! = EOF) {printf ("%. 7lf \ n", QT ();} return 0 ;}

  

ACM learning process -- hdu5017 ellipsoid (Simulated Annealing) (2014 Xi 'an online competition K questions)

Contact Us

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.