hdu 5017 Ellipsoid
来源:互联网 发布:詹姆斯戈德斯坦 知乎 编辑:程序博客网 时间:2024/05/21 20:26
Ellipsoid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1028 Accepted Submission(s): 364
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 (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
代码:
#include<cstdio>#include<iostream>#include<cmath>#include<stdlib.h>#include<ctime>#define eps 1e-8using namespace std;double a,b,c,d,e,f;const double inf=1LL<<60;int dx[]={-1,-1,-1,0,0,1,1,1};int dy[]={-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 ta=c,tb=d*y+e*x,tc=a*x*x+b*y*y+f*x*y-1; double delta=tb*tb-4*ta*tc; if(delta<0) return inf; double z1=(-tb+sqrt(delta))/(2*ta); double z2=(-tb-sqrt(delta))/(2*ta); return z1*z1<z2*z2?z1:z2;}void solve(){ double x=0,y=0,z=getz(x,y),delta=0.8; while(delta>eps){ for(int i=0;i<8;i++){ double tx=x+dx[i]*delta, ty=y+dy[i]*delta, tz=getz(tx,ty); if(tz>inf/10) continue; if(dis(tx,ty,tz)-dis(x,y,z)<0) x=tx,y=ty,z=tz; } delta*=0.99; } printf("%.7f\n",dis(x,y,z));}int main(){ srand((unsigned)time(NULL)); while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)){ solve(); }return 0;}
0 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(模拟退火)
- HDU - 5017 Ellipsoid(模拟退火法)
- HDU 5017 Ellipsoid 模拟退火第一题
- HDU 5017 Ellipsoid(模拟退火)
- hdu 5017 Ellipsoid(模拟退火)
- 关于vs2012创建cocos2d-x中控件遇到的问题
- 道里云毛文波:网络虚拟化与SDN实现Docker连通
- android开发步步为营之31:TabActivity的用法Tab显示在底部
- Python下的scipy,matplotlib,Numpy,six安装
- 让你的 Qt 桌面程序看上去更加 native(一):简介
- hdu 5017 Ellipsoid
- Bitmap 图片格式并用 C++ 读写 Bitmap
- DRM in Android
- iOS小米遥控器的手势监听及UI实现
- 64位Windows 7使用MyEclipse 9.0注册机无法获取System ID的解决办法
- 树状数组求逆序数
- 菜鸟成长记1.1.1
- linux下用户及用户组的管理
- 代码管理工具