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 ...
随机推荐
- 删除反复行SQL举例
删除反复行SQL实验简单举例 说明:实验按顺序进行.前后存在关联性.阅读时请注意.打开文件夹更便于查看. 构造实验环境: SQL> select count(*) from emp; COU ...
- 把握linux内核设计思想(二):硬中断及中断处理
[版权声明:尊重原创.转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 操作系统负责管理硬件设备.为了使系统和硬件设备的协同工作不减少机器性能.系统和 ...
- 根据URL发起HTTP请求,我的HTTPHelper。
完整的demo using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- 输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如:4 4 4 4-joker JOKER 请比较两手牌大小,输出较大的牌,如果不存在比较关系则输出ERROR
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...
- Linux下比较常用的svn命令
svn: command not found yum install -y subversion 以下是一些常用命令的使用方法,希望对大家有所帮助. 1,check out(co)签出代码 test. ...
- struts2_6_多个struts配置文件的应用
在大部分应用里,随着应用规模的添加,系统中Action的数量也会大量添加.导致struts.xml配置文件变的很臃肿,为了避免struts.xml文件过于庞大.臃肿,提高struts.xml文件的可读 ...
- Android 异常解决方法【汇总】
(1)异常:Android中引入第三方Jar包的方法(Java.lang.NoClassDefFoundError解决办法) 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方 ...
- python 基础 7.6 sys 模块
一.sys 模块 sys 模块主要功能是获取参数 [root@www pythonscripts]# cat 2.py #!/usr/bin/python #coding=utf-8 im ...
- Dubbo服务集群,常见容错机制:failover ,failsafe,failfase ,failback,forking
http://blog.csdn.net/hongweigg/article/details/52925920 http://m.blog.csdn.net/article/details?id=51 ...
- 九度OJ 1029:魔咒词典 (排序)
时间限制:5 秒 内存限制:32 兆 特殊判题:否 提交:4574 解决:1318 题目描述: 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部 ...