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

HDU - 5017 Ellipsoid(模拟退火法)的更多相关文章

  1. HDU 5017 Ellipsoid 模拟退火第一题

    为了补这题,特意学了下模拟退火算法,感觉算法本身不是很难,就是可能降温系数,步长等参数不好设置. 具体学习可以参见: http://www.cnblogs.com/heaad/archive/2010 ...

  2. HDU - 5017 Ellipsoid(模拟退火)

    题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...

  3. hdu 5017 Ellipsoid(西安网络赛 1011)

    Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  4. hdu 5017 模拟退火算法

    hdu 5017 http://blog.csdn.net/mypsq/article/details/39340601 #include <cstdio> #include <cs ...

  5. hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> ...

  6. hdu 5017 模拟退火

    题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就

  7. HDU 2609 最小表示法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...

  8. HDU 4162 最小表示法

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...

  9. 【HDOJ】5017 Ellipsoid

    简单地模拟退火. /* 5017 */ #include <cstdio> #include <cstring> #include <cstdlib> #inclu ...

随机推荐

  1. 1.2(Spring学习笔记)Spring中的Bean

    一.<Bean>的属性及子元素 在1.1中我们对<Bean>有了初步的认识,了解了一些基本用法. 现在我们进一步理解<Bean>属性及子元素. 我们先来看下< ...

  2. Exercise01_02

    public class Five{ public static void main(String[] args){ for(int i=0;i<5;i++){ System.out.print ...

  3. 关于Block Formatting Context--BFC和IE的hasLayout(转)

    转文请标明 --- 出处:穆乙 http://www.cnblogs.com/pigtail/ 一.BFC是什么? BFC(Block Formatting Context)直译为“块级格式化范围”. ...

  4. Chrome插件在页面上直接绑定JavaScript事件提示Refused to execute inline event handler because it violates the following Co

    Chrome插件问了安全是不提倡在页面上直接写JavaScript的,如果出现了这个提示,其实也没有什么,同样可以运行. 从Chrome Extenstion V2开始,不允许执行任何inline j ...

  5. MySQL查询时区分大小写(转)

    说明:在MySQL查询时要区分大小写会涉及到两个概念character set和collation,这两个概念在表设计时或者在查询时都可以指定的,详细参考:http://www.cnblogs.com ...

  6. Oracle TRCA 工具 说明 10046

    本篇文章主要介绍了"Oracle TRCA 工具 说明 ",主要涉及到Oracle TRCA 工具 说明 方面的内容,对于Oracle TRCA 工具 说明 感兴趣的同学可以参考一 ...

  7. C# log4net打不出日志 (IIS项目)

    配置文件都配了,引用也引用了,调用也是对的,网上找博客也找不到,疯掉了. 后来腆着脸问了一个前辈,他告诉我的,添完就好了. 给项目的这个文件,添加这行代码: [assembly: log4net.Co ...

  8. csharp 面向对象编程

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Shap ...

  9. Sqoop操作实践

    Sqoop操作实践 @(Hadoop) Sqoop常用参命令 序号 命令/command 类 说明 1 impor ImportTool 从关系型数据库中导入数据(来自表或者查询语句)到HDFS中 2 ...

  10. [TypeScript] Export public types from your library

    If you're a library author, it's useful to expose your public types as interfaces, to allow your con ...