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

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.
1 0.04 0.01 0 0 0
1.0000000
题意:求椭圆上离圆心近期的点的距离。
思路:模拟退火法,学着网上写的
#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(模拟退火法)的更多相关文章
- HDU 5017 Ellipsoid 模拟退火第一题
为了补这题,特意学了下模拟退火算法,感觉算法本身不是很难,就是可能降温系数,步长等参数不好设置. 具体学习可以参见: http://www.cnblogs.com/heaad/archive/2010 ...
- HDU - 5017 Ellipsoid(模拟退火)
题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...
- hdu 5017 Ellipsoid(西安网络赛 1011)
Ellipsoid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- hdu 5017 模拟退火算法
hdu 5017 http://blog.csdn.net/mypsq/article/details/39340601 #include <cstdio> #include <cs ...
- hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离
http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> ...
- hdu 5017 模拟退火
题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就
- HDU 2609 最小表示法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...
- HDU 4162 最小表示法
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...
- 【HDOJ】5017 Ellipsoid
简单地模拟退火. /* 5017 */ #include <cstdio> #include <cstring> #include <cstdlib> #inclu ...
随机推荐
- 6.4(java学习笔记)转换流
一.乱码问题 我们来看下列例子: public class ConStream { //当前平台默认采用GBK public static void main(String[] args){ Stri ...
- log4j.properties配置详解与实例-全部测试通过
最近使用log4j写log时候发现网上的写的都是千篇一律,写的好的嘛不全,写的全一点的嘛没有一点格式,看着累.这里把网上收集到的整理了一下,并且全部都在机器上测试成功了.这么好的文档估计没有了吧? # ...
- 设置MySQL数据库名不区分大小写
Linux下的MySQL默认是区分表名大小写的,通过如下设置,可以让MySQL不区分表名大小写: 1.用root登录,修改 /etc/my.cnf: 2.在[mysqld]节点下,加入一行: lowe ...
- 微信 JS SDK 的 chooseImage 接口在部分安卓机上容易造成页面刷新
该问题的症状是,当调用 chooseImage 接口并选择拍照,选择照片确定之后,然后从相机返回后,当前web页面就刷新了一次,导致拍照的图片无法选择上传:但是如果直接从相册中选择图片,则不会出现这个 ...
- 一个 关于 case when的SQL
[例]从stud_grade表中查询所有同学考试成绩情况,凡成绩为空者输出“未考”.小于60分输出“不及格”.60分至70分输出“及格”.70分至90分输出“良好”.大于或等于90分时输出“优秀”. ...
- scrapy安装使用教程
1. 安装Python,我用的是Python2.7.11,你喜欢用什么版本,你开心就好,只是后面的软件有些可能需要配套. 2. 安装pip,下载pip-8.1.2.tar.gz (md5, pgp). ...
- iOS:地图笔记
地图笔记 01. CLLocation -------------------------------------------------------- CLLocationManager 定位管理者 ...
- 一起來玩鳥 Starling Framework(3)Button!
週末夜來介紹個簡單的DisplayObject就好.不論是在電腦上或行動裝置上,跟使用者互動次數最多的,大概就是按鈕了.因此,Starling有個Button類別,來做出這個常用的互動元件. 同樣是因 ...
- 转:ios学习指南
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Franz Fang链接:https://www.zhihu.com/question/20264108/answer/302 ...
- 深入解析淘宝Diamond之客户端架构
转载:http://blog.csdn.net/u013970991/article/details/52088350 一.什么是Diamond diamond是淘宝内部使用的一个管理持久配置的系统, ...