HDOJ 5017 Ellipsoid
第一次尝试模拟退火.....
Ellipsoid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 916 Accepted Submission(s): 305
Special Judge

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 double eps=1e-8;
const double r=0.99;
const int dir_x[8]={0,0,1,-1,1,-1,1,-1};
const int dir_y[8]={1,-1,0,0,-1,1,1,-1}; double a,b,c,d,e,f; double DIST(double x,double y,double z)
{
return sqrt(x*x+y*y+z*z);
} double getZ(double x,double y)
{
double A=c,B=e*x+d*y,C=a*x*x+b*y*y+f*x*y-1;
double delta=B*B-4*A*C;
if(delta<0) return 1e60;
double z1=(-B+sqrt(delta))/2/A;
double z2=(-B-sqrt(delta))/2/A;
if(z1*z1<z2*z2) return z1;
return z2;
} double solve()
{
double step=1;
double x=0,y=0,z;
while(step>eps)
{
z=getZ(x,y);
for(int i=0;i<8;i++)
{
double nx=x+dir_x[i]*step;
double ny=y+dir_y[i]*step;
double nz=getZ(nx,ny);
if(nz>1e30) continue;
if(DIST(nx,ny,nz)<DIST(x,y,z))
{
x=nx;y=ny;z=nz;
}
}
step=step*r;
}
return DIST(x,y,z);
} int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
{
printf("%.8lf\n",solve());
}
return 0;
}
HDOJ 5017 Ellipsoid的更多相关文章
- 【HDOJ】5017 Ellipsoid
简单地模拟退火. /* 5017 */ #include <cstdio> #include <cstring> #include <cstdlib> #inclu ...
- hdu 5017 Ellipsoid(西安网络赛 1011)
Ellipsoid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU - 5017 Ellipsoid(模拟退火法)
Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance bet ...
- HDU 5017 Ellipsoid 模拟退火第一题
为了补这题,特意学了下模拟退火算法,感觉算法本身不是很难,就是可能降温系数,步长等参数不好设置. 具体学习可以参见: http://www.cnblogs.com/heaad/archive/2010 ...
- HDU - 5017 Ellipsoid(模拟退火)
题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...
- NOIp2018停课刷题记录
Preface 老叶说了高中停课但是初中不停的消息后我就为争取民主献出一份力量 其实就是和老师申请了下让我们HW的三个人听课结果真停了 那么还是珍惜这次机会好好提升下自己吧不然就\(AFO\)了 Li ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- Lua 脚本语法说明(转)
Lua脚本语法说明(增加lua5.1部份特性) Lua 的语法比较简单,学习起来也比较省力,但功能却并不弱. 所以,我只简单的归纳一下Lua的一些语法规则,使用起来方便好查就可以了.估计看完了,就懂得 ...
- UVA 1546 - Complete the sequence!(差分法)
UVA 1546 - Complete the sequence! 题目链接 题意:给定多项式前s项,求出后c项,要求尽量小 思路:利用差分法,对原序列求s - 1次差分,就能够发现规律,然后对于每多 ...
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
Harry Potter and the Hide Story Problem Description iSea is tired of writing the story of Harry Pott ...
- fcitx
安装完成后首先面对的问题是全英文无法显示汉字和输入汉字的问题.需要找到光盘上的2个中文支持字体包安装上即可.文件名如下,注意不同版本文件明后面数字部分可能会不同,其代表版本号.下面是Red Hat E ...
- 接近带给你AngularJS - 经验说明示例
接近带给你AngularJS列: 带你走近AngularJS - 基本功能介绍 带你走近AngularJS - 体验指令实例 带你走近AngularJS - 创建自己定义指令 ------------ ...
- js比量undefined种类
js比量undefined种类 if (reValue== undefined) { alert("undefined"); } 发现推断不出来.最后查了下资料要用type ...
- Unity3D-RPG项目实战(1):发动机的特殊文件夹
前言 从8月份開始.下定决心正式開始学习Unit3D啦.尽管自己写过两代端游引擎,被应用的项目也超过10个,Unreal Engine也搞过几年,只是做手游.哥确实还是个新手.Unity3D这个引擎我 ...
- 懵懵懂懂初识J2EE
一.定义 Java2平台包含:标准版.企业版.微缩版.当中J2SE是Java2的标准版,主要用 于桌面应用软件的编程:J2ME是微缩版,主要应用于嵌入式系统开发:还有这次学习的J2EE是Java2的企 ...
- 漫话Unity3D(三)
八.预制(Prefab) 这个单独提出来,是由于它太经常使用了.也是Unity 的核心要素之中的一个.原本Unity中的一个物体是你拖拽一个模型到场景中,或者创建一个几何体,或者灯光地形等,然后设置这 ...
- Android UI法宝发展Angrytools
最近很多人问我,个人App开发商如何设计UI. 其实这是个人开发者最头疼,谁在搞技术,真的不能做的一切.不可能花大量的时间去切图,去做原型设计,去做美工. 当然,尽管我们设计不出那么复杂,静止的UI. ...