标签:des style http color io os java ar strong
1 0.04 0.01 0 0 0
1.0000000
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <string> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef long long LL; #define REP(_,a,b) for(int _ = (a); _ <= (b); _++) const double eps = 1e-10; const double P = 0.99;//退火速度 const int dirX[9] = {0,1,-1,1,-1,0,0,1,-1}; const int dirY[9] = {0,1,-1,-1,1,1,-1,0,0}; double a,b,c,d,e,f; int dcmp(double x) { if(fabs(x) < eps) return 0; else if(x < 0) return -1; else return 1; } bool getRoot(double a,double b,double c,double &x1) { double delta = b*b-4*a*c; if(dcmp(delta) < 0) return false; x1 = (-b+sqrt(delta))/(a*2); return true; } void solve() { double step = 0.1; double x = 0, y = 0; double ans = 1/c; while(step > eps) { int dir = 0; REP(i,1,8) { double xx = x + step*dirX[i]*1.0; double yy = y + step*dirY[i]*1.0; double zz; if(getRoot(c,d*yy+e*xx,a*xx*xx+b*yy*yy+f*xx*yy-1,zz)) { if(xx*xx+yy*yy+zz*zz < ans) { dir = i; ans = xx*xx+yy*yy+zz*zz; } } } if(dir != 0) { x += step*dirX[dir]; y += step*dirY[dir]; } step *= P; } printf("%.8lf\n",sqrt(ans)); } int main(){ while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)) { solve(); } return 0; }
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/mowayao/article/details/39498805