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

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. Linux - 配置SSH免密通信 - “ssh-keygen”的基本用法

    目录 1 什么是SSH 2 配置SSH免密登录 2.1 安装必需的软件 2.2 ssh-keygen创建公钥-私钥对 2.3 ssh-copy-id把A的公钥发送给B 2.4 在A服务器上免密登录B服 ...

  2. scrollview gridview

    package com.fangdamai.salewinner.ui.customer; import android.content.Context;import android.content. ...

  3. activiti自己定义流程之Spring整合activiti-modeler实例(六):启动流程

    1.启动流程并分配任务是单个流程的正式開始,因此要使用到runtimeService接口.以及相关的启动流程的方法.我习惯于用流程定义的key启动,由于有多个版本号的流程定义时,用key启动默认会使用 ...

  4. 升级webapi依赖的Newtonsoft.json的版本(转)

    随着微软日渐重视开源社区的贡献,微软在自己的产品中往往也会集成开源的第三方库. 比如System.Net.Http.Foramatting.dll 就依赖于Newtonsoft.json v4.5. ...

  5. 我的Android进阶之旅------>android视频播放只有声音无画面的解决办法

    今天调试公司用VideoView实现的播放器来播放视频的时候,只有声音输出而无画面输出.一开始以为是自己程序有问题,调试了半天无果.怀疑是真机本身的问题,于是下了几个第三方的播放器来进行视频播放,例如 ...

  6. python数据分析之:绘图和可视化

    在数据分析领域,最出名的绘图工具就是matlib.在Python同样有类似的功能.就是matplotlib.前面几章我们都在介绍数据的生成,整理,存储.那么这一章将介绍如果图形化的呈现这些数据.来看下 ...

  7. cordova 插件创建

    peng@PENG-PC /E/_My_File_____/_work/MyCode/myCode/cordova-workspace/plugman-test/ABCD $ npm install ...

  8. sap 图标查看

    showicon这个程序很不错,可以显示SAP里所有的ICON(图标). 用事务码SE38直接运行程序:showicon 即可. 显示列表之后,双击任何一个图标可以显示出每一个图标的详细信息.

  9. 使用 Docker LNMP 部署 PHP 运行环境

    简介 Docker LNMP 是基于 Docker 的 PHP 集成开发环境. Github 地址:https://github.com/YanlongMa/docker-lnmp 包含软件 ngin ...

  10. SpringBoot学习笔记(12):计划任务

    SpringBoot学习笔记(12):计划任务 计划任务 在企业的实践生产中,可能需要使用一些定时任务,如月末.季末和年末需要统计各种各样的报表,每周自动备份数据等. 在Spring中使用定时任务 1 ...