题意

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

题解

模拟退火。

把\(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. 有趣的 验证JS只能输入正整数

    <html> <head> <title>只能输入正整数</title> </head> <body> 兑换数量:<inp ...

  2. 《疯狂动物城》主题曲《TryEverything》中文翻译

    <疯狂动物城>主题曲<TryEverything>夏奇拉激情献唱,很多事情是需要是试试,不试试就不知道可以成功. Oh oh oh oh oooh 哦哦哦哦哦 Oh oh oh ...

  3. 【Java/Android性能优 4】PreloadDataCache支持预取的数据缓存,使用简单,支持多种缓存算法,支持不同网络类型,扩展性强

    本文转自:http://www.trinea.cn/android/preloaddatacache/ 本文主要介绍一个支持自动向前或向后获取新数据的缓存的使用及功能.Android图片内存缓存可见I ...

  4. Spring MVC的高级配置

    1.文件上传配置 文件上传是项目中常用的一个功能,Spring MVC通过配置一个MultipartResolver来上传文件. 在Spring的控制器中,通过MultipartFile file 来 ...

  5. C# sftp通过秘钥上传下载

    一.适用场景 我们平时习惯了使用ftp来上传下载文件,尤其是很多Linux环境下,我们一般都会通过第三方的SSH工具连接到Linux,但是当我们需要传输文件到Linux服务器当中,很多人习惯用ftp来 ...

  6. sql队伍的胜负情况

    1.数据显示情况 2.sql语句执行情况 USE [数据库名] GO /****** Object: Table [dbo].[测试] Script Date: 08/03/2017 10:58:02 ...

  7. python 之 BeautifulSoup 常用提取

    一.bs4信息提取后返回的数据类型 soup.find('tbody') ---> 返回结构是一个bs4.element.Tag soup.find('tbody').children ---& ...

  8. Redis常用特性

    发布订阅 ·服务器状态在pubsub_channels字典保存了所有频道的订阅关系:SUBSCRIBE命令负责将客户端和被订阅的频道关联到这个字典里面,而UNSUBSCRIBE命令则负责解除客户端和被 ...

  9. java之接口相关知识

    1.接口用interface来声明 //定义一个动物接口 public interface Animal{ public void eat(); public void travel(); } 2.接 ...

  10. 深入理解计算机系统_3e 第九章家庭作业 CS:APP3e chapter 9 homework

    9.11 A. 00001001 111100 B. +----------------------------+ | Parameter Value | +--------------------- ...