HDU 5017 Ellipsoid (计算几何,模拟退火)
来源:互联网 发布:ubuntu arm 国内源 编辑:程序博客网 时间:2024/05/22 17:30
Ellipsoid
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 (x1,y1,z1) and (x2,y2,z2) is defined as
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 (x1,y1,z1) and (x2,y2,z2) 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.
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
2014 ACM/ICPC Asia Regional Xi'an Online
Recommend
hujie
题目大意:
求一个椭球面上的一个点到原点的最短距离。
解题思路:
模拟退火,不多解释了。
解题代码:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;const double eps=1e-8;const double INF=1e100;const int offx[]={1,0,-1,0,1,-1,-1,1};const int offy[]={0,1,0,-1,1,1,-1,-1};double a,b,c,d,e,f;double getAns(double x,double y){ double A=c,B=d*y+e*x,C=a*x*x+b*y*y+f*x*y-1.0; double delta=B*B-4*A*C; if(delta<0) return INF+10; delta=sqrt(delta); double z1=(-B+delta)/(2*A),z2=(-B-delta)/(2*A); return min( sqrt(x*x+y*y+z1*z1) , sqrt(x*x+y*y+z2*z2) );}double tosolve(double sx,double sy){ double x=sx,y=sy,ans=getAns(sx,sy),step=1e6; while(step>eps){ double sx=x,sy=y; bool flag=false; for(int i=0;i<8;i++){ double dx=x+offx[i]*step,dy=y+offy[i]*step; double tmp=getAns(dx,dy); if(tmp>=INF) continue; if(tmp<ans){ ans=tmp; flag=true; sx=dx,sy=dy; } } x=sx,y=sy; if(!flag) step/=2; } return ans;}void solve(){ //cout<<tosolve(0,0)<<" "<<tosolve(sqrt(1.0/a),0)<<" "<<tosolve(0,sqrt(1.0/b))<<endl; double ans=tosolve(0,0),tmp; tmp=tosolve(sqrt(1.0/a),0); if(tmp<ans) ans=tmp; tmp=tosolve(-sqrt(1.0/a),0); if(tmp<ans) ans=tmp; tmp=tosolve(0,sqrt(1.0/b)); if(tmp<ans) ans=tmp; tmp=tosolve(0,-sqrt(1.0/b)); if(tmp<ans) ans=tmp; printf("%.7lf\n",ans);}int main(){ while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){ solve(); } return 0;}
3 0
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- HDU 5017 Ellipsoid(退火模拟)
- HDU 5017 Ellipsoid(模拟退火算法)
- hdu 5017 Ellipsoid(模拟退火)
- HDU 5017 Ellipsoid(模拟退火)
- hdu 5017 Ellipsoid(模拟退火)
- [HDU 5017] Ellipsoid (模拟退火)
- hdu 5017 ellipsoid 模拟退火
- HDU 5017 Ellipsoid(模拟退火)
- hdu 5017 Ellipsoid 模拟退火
- hdu 5017 Ellipsoid 模拟退火
- hdu 5017 Ellipsoid 模拟退火算法模板
- HDU 5017 Ellipsoid 模拟退火第一题
- hdu 5017 Ellipsoid 模拟退火||三分
- hdu5017 Ellipsoid(模拟退火)
- hdu 5017 Ellipsoid 模拟退火算法 西安网络赛
- hdu 5017 ellipsoid 退火大法
- HDU 3644 计算几何 模拟退火
- 深入理解javascript原型和闭包(14)--从自由变量到作用域链
- 【原创】关于C#访问修饰符protected internal的说明
- 关于反编译apk出现Exception in thread "main" java.lang.ClassCastException: ....
- 2014诺贝尔生理学或医学奖揭晓
- acdream 1431 Sum vs Product
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- 20141006
- 最短编辑距离 poj3356
- git 图解Git/图形化的Git参考手册
- VS2005下编译Lua源代码
- 使用INTERVAL DAY TO SECOND类型
- 实验一: VC编程工具的灵活使用
- andorid cocos2d 游戏开发入门学习经验之总结
- bzoj 1146 - Network