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. [Interview]读懂面试问题,在面试官面前变被动为主动

    面试是供需双方心理的较量,作为求职者来说,了解对方问题的内涵,做到“明明白白他的心”,就能变被动为主动.因此,读懂面试问题,掌握面试考官的提问的目的,有准备.有针对性地回答,对提高应聘的成功率是有很大 ...

  2. Java高级架构师(一)第30节:把应用部署到Linux服务器上

  3. Java高级架构师(一)第13节:Spring MVC实现Web层开发

    package com.sishuok.architecture1.customermgr.web; import org.springframework.beans.factory.annotati ...

  4. HashMap源码-Basic hash bin node

    /** * Basic hash bin node, used for most entries. (See below for * TreeNode subclass, and in LinkedH ...

  5. JavaScript跳转到页面某个锚点#

    JavaScript跳转到页面某个锚点: scroll(0, document.getElementById('锚点ID').offsetTop);

  6. 【Node.js】3.Node.js和commomJS规范

    来源:http://javascript.ruanyifeng.com/ 目录 概述 module对象 module.exports属性 exports变量 AMD规范与CommonJS规范的兼容性 ...

  7. vertica数据库怎么查看连接数是否已经达到最大值

  8. ES6笔记之参数默认值(译)

    原文链接:http://dmitrysoshnikov.com/ 原文作者:Dmitry Soshnikov 译者做了少量补充.这样的的文字是译者加的,可以选择忽略. 作者微博:@Bosn 在这个简短 ...

  9. python 列表合并

    列表合并主要有以下方法: 1.用list的extend方法,L1.extend(L2),该方法将参数L2的全部元素添加到L1的尾部 结果:[1, 2, 3, 4, 5, 1, 20, 30] 2.用切 ...

  10. Qt Creator 乱码问题

    当 把linux下的 ,QTproject文件移植到 Windows下时. 出现上图的 乱码现象.  为了,避免因为Windows下和Linux下编码不同,而产生的中文字符乱码的问题,需统一将代码中的 ...