Ellipsoid

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

Total Submission(s): 850    Accepted Submission(s): 271

Special Judge

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
 

第一次了解模拟退火。

求z时已知x,y转化为关于z的二次方程,用韦达定理求z。

关于退火速度,測了一下,r=0.99时是281ms,r=0.98时是140ms,r=0.97时是93ms,r=0.96时就wa了。

代码:、

//97ms
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int dx[8]={0,0,1,-1,1,-1,1,-1};
const int dy[8]={1,-1,0,0,-1,1,1,-1};
const double r=0.97;
const double eps=1e-8;
double a,b,c,d,e,f;
double dis(double x,double y,double z)
{
return sqrt(x*x+y*y+z*z);
}
double getz(double x,double y)//求z
{
double A=c;
double B=d*y+e*x;
double C=f*x*y+a*x*x+b*y*y-1;
double delta=B*B-4*A*C;
if(delta<0)
{
return 1e30;
}
else
{
double z1=(-B+sqrt(delta))/A/2;
double z2=(-B-sqrt(delta))/A/2;
return z1*z1<z2*z2?z1:z2;
}
}
double anneal()//退火
{
double step=1;
double x=0,y=0,z;
while(step>eps)
{
z=getz(x,y);
for(int i=0;i<8;i++)
{
double xi=x+dx[i]*step;
double yi=y+dy[i]*step;
double zi=getz(xi,yi);
if(zi>1e20)
continue;
if(dis(xi,yi,zi)<dis(x,y,z))
{
x=xi;
y=yi;
z=zi;
}
}
step=step*r;
}
return dis(x,y,z);
}
int main()
{
while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f))
{
printf("%.8f\n",anneal());
}
return 0;
}

hdu 5017 Ellipsoid(西安网络赛 1011)的更多相关文章

  1. hdu5017:补题系列之西安网络赛1011

    补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...

  2. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  3. HDU 5009 Paint Pearls(西安网络赛C题) dp+离散化+优化

    转自:http://blog.csdn.net/accelerator_/article/details/39271751 吐血ac... 11668627 2014-09-16 22:15:24 A ...

  4. HDU 6200 2017沈阳网络赛 树上区间更新,求和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边 ...

  5. HDU 6199 2017沈阳网络赛 DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1 ...

  6. HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...

  7. HDU 6205 2017沈阳网络赛 思维题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...

  8. HDU 6198 2017沈阳网络赛 线形递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6198 题意:给出一个数k,问用k个斐波那契数相加,得不到的数最小是几. 解法:先暴力打表看看有没有规律 ...

  9. HDU 6201 2017沈阳网络赛 树形DP或者SPFA最长路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6201 题意:给出一棵树,每个点有一个权值,代表商品的售价,树上每一条边上也有一个权值,代表从这条边经过 ...

随机推荐

  1. 【IACV】边缘检测技术传统的方法与理论

    1.边缘检测的目的 边缘检测是图像分析中使用到的最常见的操作之一,而且相比其他任何主题来说,文献中提到的与边缘增强(edge enhancement)[1]与边缘检测(edge detection)[ ...

  2. DM8168硬件平台

    DM8168硬件平台  作者:Marvin_wu TMS320DM8168是一款多核SoC,它集成了包含ARM Cortex A8.DSP C674X+.M3 VIDEO.M3 VPSS等处理器.DS ...

  3. Android菜鸟的成长笔记(5)——Android系统源代码你下载了吗?

    原文:Android菜鸟的成长笔记(5)--Android系统源代码你下载了吗? 在上一篇中我们用Android系统源代码分析了我们前面写的代码,有的朋友可能就会问怎么才能下载到Google官方的源代 ...

  4. SPOJ375(树链剖分)

    题目:Query on a tree 题意:给定一棵树,告诉了每条边的权值,然后给出两种操作: (1)把第i条边的权值改为val (2)询问a,b路径上权值最大的边 分析:本题与HDU3966差不多, ...

  5. CArray

    CArray是windows下的相当于动态数组的模板类.用起来及其方便,近期由于需要在JNI下的C语言中使用,自己参考CArray类函数,及其自己需要使用到的部分函数用C++实现出来,以供自己使用,在 ...

  6. Delaunay三角剖分算法

    在图像处理中,经常会使用到三角剖分算法: 具体定义及其算法可以参考:http://baike.so.com/doc/5447649.html 下面放出来代码: Delaunay接口为存C: 测试是使用 ...

  7. HUST 1569(Burnside定理+容斥+数位dp+矩阵快速幂)

    传送门:Gift 题意:由n(n<=1e9)个珍珠构成的项链,珍珠包含幸运数字(有且仅由4或7组成),取区间[L,R]内的数字,相邻的数字不能相同,且旋转得到的相同的数列为一种,为最终能构成多少 ...

  8. win7如何清理图标缓存

    rem 关闭Windows外壳程序explorer taskkill /f /im explorer.exe rem 清理系统图标缓存数据库 attrib -h -s -r "%userpr ...

  9. Company Story | Vistaprint

    Company Story | Vistaprint Company Story A Gap in the Small Business Marketplace It’s rare that a hi ...

  10. 架设FLASH视频流server心得

    什么样的情况下才使用FMS?有下面几种情形的时候,你可能须要用到FMS 1.须要通过Flash Player 播放视频,而视频是以流的方式,而不是http渐进式下载的方式进行播放的时候.渐进式下载就是 ...