题意

给一个三维椭球面,求球面上距离原点最近的点。输出这个距离。

题解

模拟退火。

把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\)。

代码

//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream> #define FOPI freopen("in.txt", "r", stdin)
#define FOPO freopen("out.txt", "w", stdout) using namespace std;
typedef long long LL;
const int maxn = 100 + 5;
const double eps = 1e-3;
const int inf = 0x3f3f3f3f;
const double start_T = 10000; struct Point
{
double x, y, z;
Point() {}
Point(double _x, double _y, double _z):x(_x), y(_y), z(_z) {}
}; double a, b, c, d, e, f; int dx[] = {1, 1, 1, -1, -1, -1, 0, 0},
dy[] = {0, 1, -1, 0, 1, -1, -1, 1}; int n; double dist(Point a)
{
return sqrt(a.x*a.x + a.y*a.y + a.z*a.z + 1e-8);
} double getz(double x, double y)
{
double A = c, B = d*y + e*x, C = a*x*x + b*y*y + f*x*y - 1;
double delta = B*B - 4*A*C;
if (delta < -eps) return inf+1;
double z1 = (-B + sqrt(delta)) / 2 / A,
z2 = (-B - sqrt(delta)) / 2 / A;
return dist(Point(x, y, z1)) < dist(Point(x, y, z2)) ? z1 : z2;
} double SA()
{
Point p(0, 0, getz(0, 0)), to;
double ans = dist(p), rate = 0.98, T = start_T;
while(T > eps)
{
double fx, fy, fz;
double tmp = inf;
for (int aim = 0; aim < 8; aim++)
{
fx = (p.x+1.0*dx[aim]/start_T*T);
fy = (p.y+1.0*dy[aim]/start_T*T); //printf("%f\n", T); fz = getz(fx, fy);
if (fz >= inf) continue; double d = dist(Point(fx, fy, fz));
if (d < tmp)
{
tmp = d;
to = Point(fx, fy, fz);
}
} if (tmp < ans)
{
ans = tmp;
p = to;
}
else if ((rand()%10000)/10000.0 < exp((ans-tmp)/ T * start_T))
{
ans = tmp;
p = to;
}
T *= rate;
}
return ans;
} int main()
{
// FOPI;
srand(time(NULL));
while(~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f))
printf("%.7f\n", SA());
}

HDU - 5017 Ellipsoid(模拟退火)的更多相关文章

  1. HDU 5017 Ellipsoid 模拟退火第一题

    为了补这题,特意学了下模拟退火算法,感觉算法本身不是很难,就是可能降温系数,步长等参数不好设置. 具体学习可以参见: http://www.cnblogs.com/heaad/archive/2010 ...

  2. HDU - 5017 Ellipsoid(模拟退火法)

    Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distance bet ...

  3. hdu 5017 Ellipsoid(西安网络赛 1011)

    Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  4. hdu 5017 模拟退火算法

    hdu 5017 http://blog.csdn.net/mypsq/article/details/39340601 #include <cstdio> #include <cs ...

  5. hdu 5017 模拟退火/三分求椭圆上离圆心最近的点的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> ...

  6. hdu 5017 模拟退火

    题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就

  7. 【HDOJ】5017 Ellipsoid

    简单地模拟退火. /* 5017 */ #include <cstdio> #include <cstring> #include <cstdlib> #inclu ...

  8. HDOJ 5017 Ellipsoid

    第一次尝试模拟退火..... Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java ...

  9. hdu5017 Ellipsoid (模拟退火)

    Ellipsoid 原题链接 题目描述 给定.一个要满足的椭球的方程\(ax^2+by^2+cz^2+dyz+exz+fxy=1\) 求球面上一个点到原点\((0,0,0)\)的距离最小. 有多组输入 ...

随机推荐

  1. C#对象和集合初始值设定项

    对象初始值设定项 使用对象初始值设定项,你可以在创建对象时向对象的任何可访问字段或属性分配值,而无需调用后跟赋值语句行的构造函数. 利用对象初始值设定项语法,你可为构造函数指定参数或忽略参数(以及括号 ...

  2. DataBinding 访问 3

    MVVM中的Model 我们可以用任何POJO 作为 data binding 的 Model, 但是直接修改POJO对象,不能直接更新UI android的 dataBinding 模块 给提供了通 ...

  3. Centos 6.5 添加PHP5.6-7.1的源

    centOS6.5 安装后 自带的源中php是5.3版本的,对与php一些常用的框架而言 ,已经不能满足需求了: 使用下面的源 就可以更新到php7.1版本了. # rpm -Uvh http://r ...

  4. vue实现pdf导出,解决生成canvas模糊等问题

    最近公司项目需要,利用vue实现pdf导出,从而保存到本地打印出来,说起来好像也很容易,具体要怎么实现呢? 1 .我们要添加两个模块 第一个.将页面html转换成图片 npm install --sa ...

  5. Educational Codeforces Round 51 (Rated for Div. 2)

    做了四个题.. A. Vasya And Password 直接特判即可,,为啥泥萌都说难写,,,, 这个子串实际上是忽悠人的,因为每次改一个字符就可以 我靠我居然被hack了???? %……& ...

  6. maven 搭建springMvc+mybatis

    1.在resource文件夹下创建Configure.xml <?xml version="1.0" encoding="UTF-8"?> < ...

  7. localstorage本地存储的应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. DDL与DML语句

    1. DDL语句 SQL语句:结构化查询语句,使用SQL与数据库“沟通”,完成相应的数据库操作. l DDL:数据定义语言,用来维护数据库对象 1.1 创建表 Ø CREATE:创建表 演示:创建员工 ...

  9. 【BZOJ3668】[NOI2014] 起床困难综合症(位运算思想)

    点此看题面 大致题意: 给定一些位运算操作,让你在\(0\sim m\)范围内选一个初始值,使其在经过这些运算后得到的结果最大. 前置技能:关于位运算 作为一道位运算的题,如果你不知道什么是位运算,那 ...

  10. 在RichTextBox控件中显示RTF格式文件

    实现效果: 知识运用:    RichTextBox控件的LoadFile方法 //将文件内容加载到RichTextBox控件中 public void LoadFile(string path,Ri ...