标签:模拟退火
1 0.04 0.01 0 0 0
1.0000000
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> using namespace std; const double sp=0.99,eps=1e-8; double a,b,c,d,e,f,M=1e9; double dirx[]={-1,-1,-1,0,0,1,1,1}; double diry[]={-1,0,1,-1,1,-1,0,1}; double dis(double x,double y,double z) { return sqrt(x*x+y*y+z*z); } double getz(double x,double y) { double A=0,B=0,C=0; A=c; B=d*y+e*x; C=a*x*x+b*y*y+f*x*y-1; double delta=B*B-4*A*C; if(delta<0) return M; double z1=(sqrt(delta)-B)/(2.0*A),z2=(-sqrt(delta)-B)/(2.0*A); if(z1*z1<z2*z2) return z1; return z2; } double solve() { double x=0,y=0,z=0,tx=0,ty=0,tz=0,step=1; z=getz(x,y); while(step>eps) { for(int i=0;i<8;i++) { tx=x+dirx[i]*step; ty=y+diry[i]*step; tz=getz(tx,ty); if(tz>=M) continue; if(dis(tx,ty,tz)<dis(x,y,z)) { x=tx,y=ty,z=tz; } } step*=sp; } return dis(x,y,z); } int main() { while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF) { printf("%.8lf\n",solve()); } return 0; }
标签:模拟退火
原文地址:http://blog.csdn.net/knight_kaka/article/details/39718459