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

题意:求椭圆上离圆心近期的点的距离。

思路:模拟退火法,学着网上写的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int inf = 1e8;
const double eps = 1e-8; const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,1,-1,-1};
double a, b, c, d, e, f; double dis(double x, double y, double z) {
return sqrt(x * x + y * y + z * z);
} double calz(double x, double y) {
double A = c;
double B = d * y + e * x;
double C = f * x * y + a * x * x + b * y * y - 1.0;
double delta = B * B - 4.0 * A * C; if (delta < 0.0) return inf+10.0;
delta = sqrt(delta);
double z1 = (-B + delta) / (2.0 * A);
double z2 = (-B - delta) / (2.0 * A);
if (dis(x, y, z1) < dis(x, y, z2))
return z1;
return z2;
} double solve() {
double x = 0, y = 0, z = sqrt(1.0/c);
double step = 1.0, rate = 0.99;
while (step > eps) {
for (int k = 0; k < 8; k++) {
double nx = x + step * dx[k];
double ny = y + step * dy[k];
double nz = calz(nx, ny); if (nz >= inf) continue;
if (dis(nx, ny, nz) < dis(x, y, z)) {
x = nx;
y = ny;
z = nz;
}
}
step *= rate;
}
return dis(x, y, z);
} int main() {
while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF) {
printf("%.7lf\n", solve());
}
return 0;
}

最新文章

  1. 安全测试及B/S C/S安全性比较
  2. Leetcode 69 Sqrt(x) 二分查找(二分答案)
  3. Oracle 客户端免安装数据库连接
  4. jquery基础总结
  5. linux系统tomcat启动正常访问不到主页面
  6. Android RecyclerView(瀑布流)水平/垂直方向分割线
  7. CQRS学习——最小单元的Cqrs(CommandEvent)[其一]
  8. 《Linear Algebra and Its Application》-chaper1-行化简法解决线性方程组
  9. Asp.Net EF Code First 简单入门
  10. C语言变量的存储类别
  11. 关于mwArray和一般数组的区别
  12. 查询select
  13. CSS3新增伪类汇总
  14. Git首次配置
  15. 【English】20190418
  16. Robot Framework--ride使用说明2
  17. Metasploit Framework(2)Exploit模块、Payload使用
  18. linux下静态库和动态库的制作
  19. vim中的分屏操作
  20. python接口自动化测试(一)-request模块

热门文章

  1. Exercise03_02
  2. Maven多模块项目单独编译子模块项目时报错:Failed to execute goal on project/Could not resolve dependencies for project
  3. 位图(BitMap)索引
  4. Java集合之保持compareTo和equals同步
  5. 64位的centos6.9的vnc-sever的安装及桌面环境安装
  6. php图片木马讲解
  7. SVG 基础图形
  8. uva 11584 Partitioning by Palindromes 线性dp
  9. 开源知识库管理系统选型 centos6.4 搭建knowlededgeroot-1.0.4知识库平台
  10. Windows如何自定义U盘盘符、文件夹图标、文件夹背景