标签: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 <algorithm> #include <cmath> using namespace std; const double eps=1e-8; const double r=0.99; const int dir_x[8]={0,0,1,-1,1,-1,1,-1}; const int dir_y[8]={1,-1,0,0,-1,1,1,-1}; double a,b,c,d,e,f; double DIST(double x,double y,double z) { return sqrt(x*x+y*y+z*z); } double getZ(double x,double y) { double A=c,B=e*x+d*y,C=a*x*x+b*y*y+f*x*y-1; double delta=B*B-4*A*C; if(delta<0) return 1e60; double z1=(-B+sqrt(delta))/2/A; double z2=(-B-sqrt(delta))/2/A; if(z1*z1<z2*z2) return z1; return z2; } double solve() { double step=1; double x=0,y=0,z; while(step>eps) { z=getZ(x,y); for(int i=0;i<8;i++) { double nx=x+dir_x[i]*step; double ny=y+dir_y[i]*step; double nz=getZ(nx,ny); if(nz>1e30) continue; if(DIST(nx,ny,nz)<DIST(x,y,z)) { x=nx;y=ny;z=nz; } } step=step*r; } return DIST(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; }
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/ck_boss/article/details/39398513