hdu 5017 Ellipsoid(西安网络赛 1011)
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

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
第一次了解模拟退火。
求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)的更多相关文章
- hdu5017:补题系列之西安网络赛1011
补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...
- 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 ...
- HDU 5009 Paint Pearls(西安网络赛C题) dp+离散化+优化
转自:http://blog.csdn.net/accelerator_/article/details/39271751 吐血ac... 11668627 2014-09-16 22:15:24 A ...
- HDU 6200 2017沈阳网络赛 树上区间更新,求和
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边 ...
- HDU 6199 2017沈阳网络赛 DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1 ...
- HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...
- HDU 6205 2017沈阳网络赛 思维题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...
- HDU 6198 2017沈阳网络赛 线形递推
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6198 题意:给出一个数k,问用k个斐波那契数相加,得不到的数最小是几. 解法:先暴力打表看看有没有规律 ...
- HDU 6201 2017沈阳网络赛 树形DP或者SPFA最长路
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6201 题意:给出一棵树,每个点有一个权值,代表商品的售价,树上每一条边上也有一个权值,代表从这条边经过 ...
随机推荐
- 关于wind7重新安装系统后,连接mysql的问题
系统重装对于我们来说,可以说是家常便饭了.但重装系统之后 ,又要装很多的应用软件是会很烦的.特别是重装一些数据库软件,时间长不说,搞不好数据丢失了会让人抓狂. 今天我简单介绍一个不用重装mysql的方 ...
- SqlHelper初探之二
在上一篇简单的介绍了sqlhelper的基本知识,接下来就让我们进一步学习他的实践过程. 首先:我们要明白的一件事Sqlhelper不是写出来的,而是在D层的代码中提炼出来的?那么就会反问一句“D层中 ...
- javascript创建类的6种方式
javascript创建类的7种方式 一 使用字面量创建 1.1 示例 var obj={}; 1.2 使用场景 比较适用于临时构建一个对象,且不关注该对象的类型,只用于临时封装一次数据,且不适合代码 ...
- 更好的自动ssh登录
更好的自动ssh登录 解决~/.ssh/known_hosts 过期问题. bash + expect bash:ssh.sh #!/bin/bash help(){ echo "usage ...
- UITableView性能优化及手工绘制UITableViewCell
提高表视图的性能 UITableView作为应用中最常用的视图,它的性能优化问题几乎是经常提及.下面对在非网络访问情况下的表视图性能优化进行了主要的几点说明: 1.自定义类或XIB文件时 在系统提供的 ...
- g++优化选项
g++优化选项 g++优化选项 对于下面的这段代码: 1 2 3 4 5 6 7 8 9 10 11 12 #include <iostream> using namespace std; ...
- 字符编码详解 good
字符编码详解 字符编码详解
- 开启cocos2dx 3.0的Console功能
下面内容用于自己知识的备忘,想看具体内容,请參照例如以下地址. 原英文文地址: http://discuss.cocos2d-x.org/t/cocos3-0-tutorial-console-tut ...
- django-admin.py失效的问题合集!
今早在命令行运行django-admin.py突然失效了.联想到昨天把Python的版本号由3.4降为2.7,Django由1.65降为1.5,能够是由于当中的修改造成的问题.网上搜了一下解决方式五花 ...
- A Game of Thrones(18) - Catelyn
“We will make King’s Landing within the hour.” Catelyn turned away from the rail and forced herself ...