---恢复内容开始---

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 (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
 
 
这个题目可以模拟退火来做,可以在某一点朝八个方向搜索,如果使距离变小了,自然就朝那个方向走step步长,不过步长需要随次数按比率变小。当步长到达esp,自然精度达到了要求。不过需要注意的是要判断z根不存在的情况,以及两个根取距离最小的。几次测试后step的减小系数是0.97到0.99是可以过的。
 
代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define esp 1e-7 using namespace std; bool flag;
double a, b, c, d, e, f; double getz(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 v = B*B - 4*A*C;
if (v < 0)
{
flag = 0;
return 0;
}
flag = 1;
v = sqrt(v);
double z1 = (v-B) / A / 2.0;
double z2 = (-v-B) / A / 2.0;
if (fabs(z1) < fabs(z2))
return z1;
else
return z2;
} double dis(double x, double y)
{
double z = getz(x, y);
if (flag == 0)
return 0;
return sqrt(x*x + y*y + z*z);
} double qt()//模拟退火
{
double x = 0, y = 0, Min = dis(x, y);
double xx, yy, len;
double step = 1;
while (step >= esp)
{
for (int dx = -1; dx <= 1; ++dx)
{
for (int dy = -1; dy <= 1; ++dy)
{
if (dx == 0 && dy == 0)
continue;
xx = x + step*dx;
yy = y + step*dy;
len = dis(xx, yy);
if (flag && len < Min)
{
Min = len;
x = xx;
y = yy;
}
}
}
step *= 0.97;
}
return Min;
} int main()
{
//freopen("test.txt", "r", stdin);
while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF)
{
printf("%.7lf\n", qt());
}
return 0;
}

  

ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)的更多相关文章

  1. ACM学习历程—Rotate(HDU 2014 Anshan网赛)(几何)

    Problem Description Noting is more interesting than rotation! Your little sister likes to rotate thi ...

  2. hdu 5011 nim博弈 (2014西安网赛E题)

    n堆石子,每次可以选一堆取走至少一个,之后你可以不操作或者把该堆石子分成两堆,每堆至少一个,和还是原来(取完石子后)的石子个数. Sample Input1121 131 2 3 Sample Out ...

  3. hdu 5007 水题 (2014西安网赛A题)

    题意:出现Apple.iPod.iPhone.iPad时输出MAI MAI MAI!,出现Sony,输出SONY DAFA IS GOOD! Sample InputApple bananaiPad ...

  4. ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)

    Description There is a special number sequence which has n+1 integers. For each number in sequence, ...

  5. ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)

    Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...

  6. 2014西安现场赛F题 UVALA 7040

    地址 题意:求在m种颜色中挑选k种颜色,给n个花朵涂色有几种方法. 分析:画图可以发现,基本的公式就是k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总颜色数不超过k种,并没有保证恰好出现k种 ...

  7. 异或运算(2014西安网络赛H题)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 题意:给出范围N,给出0-N的一个排列a.让你求出另外一个排列b,使 t = a1 ^ b1 + a ...

  8. CF GYM100548 (相邻格子颜色不同的方案数 2014西安现场赛F题 容斥原理)

    n个格子排成一行,有m种颜色,问用恰好k种颜色进行染色,使得相邻格子颜色不同的方案数. integers n, m, k (1 ≤n, m ≤ 10^9, 1 ≤ k ≤ 10^6, k ≤ n, m ...

  9. hdu 5053 (2014上海网赛L题 求立方和)

    题目大意:给你L到N的范围,要求你求这个范围内的所有整数的立方和. Sample Input2 //T1 32 5 Sample OutputCase #1: 36Case #2: 224 # inc ...

随机推荐

  1. refresh的停车场(栈和队列的STL)

    refresh的停车场 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述  refresh近期发了一笔横財,开了一家停车场. 因 ...

  2. Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect ...

  3. Zabbix-20160817-高危SQL注入漏洞

    漏洞概述: zabbix是一个开源的企业级性能监控解决方案.近日,zabbix的jsrpc的profileIdx2参数存在insert方式的SQL注入漏洞,攻击者无需授权登陆即可登陆zabbix管理系 ...

  4. ios --转载 使用SMSSDK实现短信验证:

    1.先到http://www.mob.com/#/网站注册账号,然后下载最新的sdk(有Android和iOS两个版本,根据需要进行下载) 2.进入到后台选择SecurityCodeSDk(支持全球短 ...

  5. 多线程快速解压FastZipArchive介绍

    本文转载至  http://blog.csdn.net/xunyn/article/details/12975937   多线程解压iosfast 在iOS项目中用到解压缩,用的是ZipArchive ...

  6. MySQL 5.7 等高版本关于JDBC驱动的几个问题

    https://blog.csdn.net/dj673344908/article/details/85223313 mysql 5.7 用8.0版本的驱动可以,5.1版本也可以,5.5.5.6.5. ...

  7. 【BZOJ3435】[Wc2014]紫荆花之恋 替罪点分树+SBT

    [BZOJ3435][Wc2014]紫荆花之恋 Description 强强和萌萌是一对好朋友.有一天他们在外面闲逛,突然看到前方有一棵紫荆树.这已经是紫荆花飞舞的季节了,无数的花瓣以肉眼可见的速度从 ...

  8. Mybatis之增删改查操作

    准备工作 建立整体项目目录 新建一个java工程,创建如下工程目录 其中com.kang.pojo中存放pojo类,com.kang.test中存放测试类. 源码目录config中存放Mybatis的 ...

  9. yarn_action

    https://maprdocs.mapr.com/home/AdministratorGuide/ResourceAllocation-YARNContainer.html yarn.schedul ...

  10. Grunt 学习笔记【1】----基础知识

    题记:虽然现在大家都在推Webpack,无奈业务需要,因此研究下Grunt. 说明:本文是基于Grunt 0.4.5版本. 一 说明 为何要用构建工具? 一句话:自动化.对于需要反复重复的任务,例如压 ...