HDU 5017 Ellipsoid(模拟退火)
来源:互联网 发布:skype回拨软件 编辑:程序博客网 时间:2024/06/09 21:58
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
【思路分析】
求椭球面上的点到原点的最短距离。网上很多说是模拟退火,个人感觉此题局部最优解就是全局最优解,即结果是一个单峰函数,顶多算个爬山算法。
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace std;#define r 0.99#define inf 1e8#define eps 1e-8double a,b,c,d,e,f;int direction[10][2];void init(){ int x = 0; for(int i = -1;i <= 1;i++) { for(int j = -1;j <= 1;j++) { direction[x][0] = i; direction[x][1] = j; x++; } }}double distances(double x,double y,double z){ return sqrt(x * x + y * y + z * z);}double caculateZ(double x,double y)//根据求二次方程原理求z{ double A = c; double B = d * y + e * x; double C = a * x * x + b * y * y + f * x * y - 1.0; double delta = B * B - 4.0 * A * C; if(delta < 0.0) return inf; else { double z1 = (-B + sqrt(delta)) / (2.0 * A); double z2 = (-B - sqrt(delta)) / (2.0 * A); if(distances(x,y,z1) < distances(x,y,z2)) return z1; else return z2; }}int main(){ init(); while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF) { double x = 0,y = 0,z = sqrt(1.0 / c); double step = 1.0; while(step > eps) { for(int i = 0;i < 9;i++) { double x1 = x + step * direction[i][0]; double y1 = y + step * direction[i][1]; double z1 = caculateZ(x1,y1); if(z1 >= inf) continue; if(distances(x1,y1,z1) < distances(x,y,z)) { x = x1; y = y1; z = z1; } } step *= r; } printf("%.7lf\n",distances(x,y,z)); } 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 模拟退火||三分
- hdu5017 Ellipsoid(模拟退火)
- hdu 5017 Ellipsoid 模拟退火算法 西安网络赛
- hdu 5017 ellipsoid 退火大法
- HDU5017 Ellipsoid 模拟退火
- WebView自适用屏幕
- Web未来设计发展的七大趋势
- pom.xml常用元素知识
- php读文件——将服务端的文件读出来显示在web页面
- ubuntu12.04 + fuerte ROS下安装xtion pro live 显示图像
- HDU 5017 Ellipsoid(模拟退火)
- sqlite3 数据库命令操作
- 几个ie6样式兼容性:1px高的块容器、PNG透明图像、负边距时后遮盖前、边框不显示等问题
- Hibernate、MyBatis的比较
- unity3d 屏幕截图多种写法
- John Carmack密码:0x5f3759df
- TM1628
- 《深入理解Java虚拟机》读书笔记——内存分配与回收策略
- 暑假-最短路(Bellman-ford、spfa)-F - Wormholes