题意

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

题解

模拟退火。

把\(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. 用cookie实现记住密码

    jsp-4 用cookie实现记住密码 这次就有点简单了 基本是jsp-3的代码但是有些修改 public void login(HttpServletRequest req, HttpServlet ...

  2. eros 修改 android上原生picker的颜色的呢

    修改选中颜色和文字颜色 修改文件如下 修改窗口底色

  3. IIS重叠回收

    在IIS应用程序池的高级设置中,有一个“禁用重叠回收”属性,默认值是False. 重叠回收(Overlapped Recycling),指的是当回收的时候,原来的进程继续处理正在处理的请求,同时一个新 ...

  4. nginx对不存在的文件进行404处理

    location / { try_files $uri $uri/ /?$args 404; } location / { try_files $uri $uri/ /index.html 404; ...

  5. leetcode——1

    1. 题目  Two Sum Given an array of integers, find two numbers such that they add up to a specific targ ...

  6. 扫描局域网ip的shell

    # vim /mysh/ipscan.sh #!/bin/bash # scan the local alive ipaddress # -- if [ -f $filename ];then ech ...

  7. 【51nod1443】路径和树(堆优化dijkstra乱搞)

    点此看题面 大致题意:给你一个无向联通图,要求你求出这张图中从u开始的权值和最小的最短路径树的权值之和. 什么是最短路径树? 从\(u\)开始到任意点的最短路径与在原图中相比不变. 题解 既然要求最短 ...

  8. 【CF1000C】Covered Points Count(离散化+差分)

    点此看题面 大致题意: 给出\(n\)条线段,分别求有多少点被覆盖\(1\)次.\(2\)次...\(n\)次. 正常的算法 好吧,这道题目确实有个很简单的贪心做法(只可惜我做的时候没有想到,结果想了 ...

  9. 站点安全预警,建议大家多重禁止load_file函数!

    比如在你的linux机器上运行 select load_file(0x2F6574632F706173737764); 看看结果是什么?这应该不是我们希望看到的. 所以我们禁用这个函数吧. 这个主要通 ...

  10. Problem K: 搜索基础之棋盘问题

    Problem K: 搜索基础之棋盘问题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 92  Solved: 53[Submit][Status][W ...