题干:

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 (x 1,y 1,z 1) and (x 2,y 2,z 2) 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

题目大意:

求椭圆上离圆心最近的点的距离。

解题报告:

先解方程,然后模拟退火。但是发现这个题无论如何也调不出样例,无奈改爬山算法。(正解是三分)

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const double eps = 1e-10;
const double GG = 12398734577LL;
const int MAX = 2e5 + 5;
int nx[8] = {1,1,1,0,0,-1,-1,-1};
int ny[8] = {1,0,-1,1,-1,1,0,-1};
double a,b,c,d,e,f;
//double Rand(){return rand()%(RAD+1)/(1.0*RAD);}//随机产生0-1的浮点数
double calz(double x,double y) {double A=c,B=(d*y+e*x),C=f*x*y+a*x*x+b*y*y-1;double det = B*B-4*A*C;if(det < 0) return GG;double z1 = (-B+sqrt(det))/(2*A);double z2 = (-B-sqrt(det))/(2*A);if(fabs(z1)<fabs(z2)) return z1;else return z2;
//  return min(z1,z2);
}
double solve(double curx,double cury) {curx=0,cury=0;double T = 1,ansdis = GG;while(T>eps) {for(int i = 0; i<8; i++) {double tx = curx + nx[i]*T;double ty = cury + ny[i]*T;double tz = calz(tx,ty);if(fabs(tz-GG) < eps) continue;double tmpdis = sqrt(tx*tx+ty*ty+tz*tz);if(tmpdis < ansdis) {ansdis = tmpdis;curx = tx;cury = ty;}}T*=0.99;}return ansdis;
}
int main()
{while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)) {double ans = 12312312313LL;ans = min(ans,solve(1/sqrt(a),0));ans = min(ans,solve(0,1/sqrt(b)));printf("%.6f\n",ans);}return 0 ;
}

【HDU - 5017】Ellipsoid(爬山算法,模拟退火,三分)相关推荐

  1. HDU - 5017 Ellipsoid(三分套三分/模拟退火)

    题目链接:点击查看 题目大意:给出一个椭球面的方程,求椭球面上的点与原点距离的最小值 题目分析:因为涉及到了求最小值,我们可以考虑三分,又因为每一个点都是三维的(x,y,z),不过z可以通过x和y的计 ...

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

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

  3. hdu 3007【爬山算法】

    题意:还是和别的一样是个模板提,给出n个点的坐标,然后求出一个点到这个点的最短距离的坐标,并输出最短距离 这个数据很水,精度要求也没有这么高 //#include<bits/stdc++.h&g ...

  4. 爬山算法和模拟退火算法简介(转)

    源:爬山算法和模拟退火算法简介 一. 爬山算法 ( Hill Climbing ) 介绍模拟退火前,先介绍爬山算法.爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为 ...

  5. 爬山法和模拟退火算法求解选址问题

    选址问题 选址问题是运筹学中经典的问题之一.选址问题在生产生活.物流.甚至军事中都有着非常广泛的应用,如工厂.仓库.急救中心.消防站.垃圾处理中心.物流中心.导弹仓库的选址等. 基本问题: P-中位问 ...

  6. 爬山算法 ( Hill Climbing )/模拟退火(SA,Simulated Annealing)

    一. 爬山算法 ( Hill Climbing ) 爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解.爬山算法实现很简单,其主要缺点是 ...

  7. 【机器学习基础】(一) 爬山算法 ( Hill Climbing )与模拟退火(SA,Simulated Annealing)

    一.爬山算法 ( Hill Climbing ) 爬山算法属于人工智能算法的一种. 这种算法基于贪心算法的思想,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解.爬山算 ...

  8. 爬山算法matlab程序,爬山算法和模拟退火算法

    爬山算法 大体思路 爬山算法即是模拟爬山的过程,随机选择一个位置爬山,每次朝着更高的方向移动,直到到达山顶 具体操作 把当前的节点和要走的节点的值进行比较. 如果当前节点是最大的,那么不进行操作:反之 ...

  9. 数学建模笔记——最优值之我见(爬山算法,模拟退火

    目录 爬山问题 爬山算法的流程 爬山算法优缺点 先提物理退火 关于模拟退火 1.1总论 1.2主要流程 1.2.1产生初始解 1.2.2扰动产生新解 1.2.3计算 1.2.4判断 1.2.4循环 2 ...

最新文章

  1. 计算机网络中st是什么,计算机组成中ST 是指什么
  2. 如何预约升级鸿蒙,超过66万人预约,华为亮出真正王牌旗舰,支持优先升级鸿蒙系统...
  3. Ubuntu 迁移 /tmp 到别的硬盘
  4. 反射工具类,如斯优雅
  5. 智能指针shared_ptr的几个例子
  6. beego——模板处理
  7. 《我的十年图像生涯》—王郑耀(西安交通大学)
  8. 开发软件不是闭卷考试
  9. java 符_java运算符
  10. [设计模式]装饰者模式
  11. qt 程序运行终端报错 D:\Program Files\SogouInput\Components\程序异常结束。
  12. Android性能测试用例
  13. Git 进行分布式管理的入门
  14. PhpMyWind储存型XSS漏洞练习(CVE-2017-12984)
  15. 人类一败涂地怎么正在连接服务器,人类一败涂地联机显示正在连接服务器解决办法...
  16. Python 处理一对多考勤表
  17. 机顶盒ttl无法输入_哪位大神帮帮忙,B860 AV1.1 TTL 无法输入命令
  18. 如何利用支付宝实现异地、跨行转账0元手续费
  19. structural covariance network
  20. linux自己制作卸载u盘程序,定制自己的U盘Linux系统

热门文章

  1. 宽字符串忽略大小写比较的实现(原)
  2. [Leedcode][JAVA][第125题][验证回文串][双指针][String]
  3. 树状数组的区间修改+查询
  4. redis存储数据类型_Redis与Memcahe的区别最全整理
  5. mysql导出数据库对象命令_mysql数据库导出数据(命令)
  6. macos php无法访问,Mac上,Apache启动正常,却无法访问localhost和127.0.0.1
  7. Redis windows学习(一)——redis安装和基础使用
  8. 云计算的认识和看法_云存储已经成为存储的未来,你的存储跟上节奏了吗?
  9. dw怎么打开html模板,Dreamweaver中如何使用模板
  10. Arm-Linux 编译Asterisk