hdu5017 Ellipsoid(模拟退火)

Ellipsoid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1225    Accepted Submission(s): 446
Special Judge


Problem Description
Given a 3-dimension ellipsoid(椭球面)

your task is to find the minimal distance between the original point (0,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 as
 

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 above. 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
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5061  5060  5059  5058  5057 


解题思路:晕,不知道怎么ac的,样例都没过。。。
#include <iostream>
#include <cstdio>
#include <time.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
double a,b,c,d,e,f;
double ans;
int di[8][2]={-1,0,-1,-1,0,-1,1,-1,1,1,1,0,1,-1,1};
void get_point(double x,double y){
    double len=1;
    while(len>1e-6){
        int dir=-1;
        for(int i=0;i<8;i++){
            double xx=x+len*di[i][0],yy=y+len*di[i][1];
            double A=c,B=d*yy+e*xx,C=a*xx*xx+b*yy*yy+f*xx*yy-1;
            double det=B*B-4*A*C;
            if(det<0) continue;
            double z=min((-B+sqrt(det))*(-B+sqrt(det)),(-B-sqrt(det))*(-B-sqrt(det)))/(4*A*A);
            if(xx*xx+yy*yy+z<ans){
                ans=xx*xx+yy*yy+z;
                dir=i;
            }
        }
        if(dir==-1) len/=2;
        else x+=len*di[dir][0],y+=len*di[dir][1];
    }
}
void solve(){
    ans=1e18;
    get_point(0,0);
    //get_point((rand()%10)*1.0/4/sqrt(a),(rand()%10)*1.0/4/sqrt(b));
    //get_point((rand()%10)*1.0/4/sqrt(a),-(rand()%10)*1.0/4/sqrt(b));
    //get_point(-(rand()%10)*1.0/4/sqrt(a),(rand()%10)*1.0/4/sqrt(b));
    //get_point(-(rand()%10)*1.0/4/sqrt(a),-(rand()%10)*1.0/4/sqrt(b));
    printf("%.7f\n",sqrt(ans));
}
int main(){
    while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)){
        solve();
    }
    return 0;
}
/*
0.25 -0.10 0.123 -0.234 0.456 -0.567
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值