Created
September 14, 2014 10:37
-
-
Save Sd-Invol/c05beb277abf48eb19be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <cmath> | |
#include <map> | |
#include <queue> | |
#include <cassert> | |
using namespace std; | |
typedef long long LL; | |
const int N = 50005; | |
double a , b , c , d , e , f; | |
double Range; | |
double pa(double X , double Y) { | |
double A = c; | |
double B = d * Y + e * X; | |
double C = a * X * X + b * Y * Y + f * X * Y - 1; | |
double D = B * B - 4 * A * C; | |
if (D < 0) return sqrt(X * X + Y * Y) + 1e10; | |
D = sqrt(D); | |
double Z1 = (-B + D) / (2 * A) , Z2 = (-B - D) / (2 * A); | |
return sqrt(X * X + Y * Y + min(Z1 * Z1 , Z2 * Z2)); | |
} | |
pair<double , double> cal(double X) { | |
double L = -Range , R = Range , m1 , m2; | |
while (R - L > 1e-10) { | |
m1 = (L + L + R) / 3; | |
m2 = (L + R + R) / 3; | |
if (pa(X , m1) < pa(X , m2)) | |
R = m2; | |
else | |
L = m1; | |
} | |
return make_pair(pa(X , (L + R) / 2) , (L + R) / 2); | |
} | |
void work() { | |
Range = min(a , min(b , c)); | |
Range = sqrt(1 / Range) + 0.5; | |
Range = 1e9; | |
double L = -Range , R = Range , m1 , m2; | |
/*for (double i = 0.9999999 ; i <= Range ; i += 0.1) { | |
printf("%f %f\n" , i , cal(i).first); | |
}*/ | |
while (R - L > 1e-10) { | |
m1 = (L + L + R) / 3; | |
m2 = (L + R + R) / 3; | |
if (cal(m1).first < cal(m2).first) | |
R = m2; | |
else | |
L = m1; | |
} | |
pair<double , double> res = cal((L + R) / 2); | |
printf("%.10f\n" , res.first); | |
} | |
int main() { | |
while (~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)) | |
work(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment