ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)
---恢复内容开始---
Description

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
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
Sample Input
Sample Output
#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题)的更多相关文章
- ACM学习历程—Rotate(HDU 2014 Anshan网赛)(几何)
Problem Description Noting is more interesting than rotation! Your little sister likes to rotate thi ...
- hdu 5011 nim博弈 (2014西安网赛E题)
n堆石子,每次可以选一堆取走至少一个,之后你可以不操作或者把该堆石子分成两堆,每堆至少一个,和还是原来(取完石子后)的石子个数. Sample Input1121 131 2 3 Sample Out ...
- hdu 5007 水题 (2014西安网赛A题)
题意:出现Apple.iPod.iPhone.iPad时输出MAI MAI MAI!,出现Sony,输出SONY DAFA IS GOOD! Sample InputApple bananaiPad ...
- ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)
Description There is a special number sequence which has n+1 integers. For each number in sequence, ...
- 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 ...
- 2014西安现场赛F题 UVALA 7040
地址 题意:求在m种颜色中挑选k种颜色,给n个花朵涂色有几种方法. 分析:画图可以发现,基本的公式就是k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总颜色数不超过k种,并没有保证恰好出现k种 ...
- 异或运算(2014西安网络赛H题)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 题意:给出范围N,给出0-N的一个排列a.让你求出另外一个排列b,使 t = a1 ^ b1 + a ...
- CF GYM100548 (相邻格子颜色不同的方案数 2014西安现场赛F题 容斥原理)
n个格子排成一行,有m种颜色,问用恰好k种颜色进行染色,使得相邻格子颜色不同的方案数. integers n, m, k (1 ≤n, m ≤ 10^9, 1 ≤ k ≤ 10^6, k ≤ n, m ...
- hdu 5053 (2014上海网赛L题 求立方和)
题目大意:给你L到N的范围,要求你求这个范围内的所有整数的立方和. Sample Input2 //T1 32 5 Sample OutputCase #1: 36Case #2: 224 # inc ...
随机推荐
- 开发ActiveX控件调用另一个ActiveX系列3——ActiveX调用另一个ActiveX
终于进入正题了,怎样在ActiveX中调用另一个ActiveX.我们的项目需要调用华视电子身份证识别仪的ActiveX控件 在这里有很多识别仪ActiveX插件下载:http://www.idukaq ...
- c# .net 关于接口实现方式:隐式实现/显式实现!
以前在用到接口时,从来没注意到接口分为隐式实现与显示实现.昨天在浏览博客时看到相关内容,现在根据自己的理解记录一下,方便日后碰到的时候温习温习. 通俗的来讲,“显示接口实现”就是使用接口名称作为方法 ...
- 卸载gnu gcj
麻辣个鸡的,我在Linux上安装的jkd版本是1.8,然后可能是之后安装了GCC吧,他大爷的,java版本变成了1.5.这个残酷的事实是在我写练习Package的测试文件的时候搞得. 机智的看了一下j ...
- Redis源码试读(一)源码准备
这里开始查看Redis的源码,之前是在看Unix的环境编程,虽然这本书写的很好,但是只看这个感觉有点隔靴搔痒.你可以知道沙子.水泥.钢筋的特性,但是要想建一栋大楼仍然是另一回事.Unix环境编程要看, ...
- Java源代码之LinkedHashMap
Java源代码之LinkedHashMap 转载请注明出处:http://blog.csdn.net/itismelzp/article/details/50554412 一.LinkedHashMa ...
- linux下压缩成zip文件解压zip文件
linux zip命令的基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] linux zip命令参数列表: -a 将文件转成ASCII模式 -F 尝试修复损坏 ...
- Swiftl优秀的特性
Swift语言在吸收诸多优秀语言如java.c++,Python之后.提供给开发人员大量优秀的特性. 以下我列举一下,swift一些优秀的特性: 1.函数使用经典的圆括号和点调用语法 2.函数标签特性 ...
- 1 zabbix3.2.4 安装
一. 搭建zabbix服务 Zabbix 3.0对PHP的要求最低为5.4,而CentOS6默认为5.3.3,完全不满足要求,故需要利用第三方源,将PHP升级到5.4以上,注意,不支持PHP7.如下是 ...
- Unix高级环境编程—进程控制(一)
一.函数fork #include<unistd.h> pid_t fork(void) ...
- eclipse中 svn出现 E220000 解决办法
这种情况,先试试修改svnserve.conf 中的 anon-access = none 然后重启eclipse 如果还是不行,还有可能是因为你修改了svn的配置链接后 跟他人的svn连接方式有 ...