HDU 5017 Ellipsoid
2014-09-15 18:11
337 查看
题意:给出三元椭圆曲面的方程,求曲面到原点的最短距离。
思路:神奇的随机化模拟退火法。
代码如下:来自/article/2651713.html
思路:神奇的随机化模拟退火法。
代码如下:来自/article/2651713.html
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int D[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; double a, b, c, d, e, f; const double INF = 1e9; const double eps = 1e-8; double dis(double x, double y, double z) { return sqrt(x * x + y * y + z * z); } double cal(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; double del = B * B - 4 * A * C; if (del < 0) return 1e10; del = sqrt(del); double z1 = (-B + del) / A / 2; double z2 = (-B - del) / A / 2; if (dis(x, y, z1) < dis(x, y, z2)) return z1; return z2; } double solve() { double x = 0, y = 0, z = sqrt(1.0 / c); double step = 1.0, r = 0.99; while (step > eps) { for (int i = 0; i < 8; i++) { double xx = x + step * D[i][0]; double yy = y + step * D[i][1]; double zz = cal(xx, yy); if (zz > INF) continue; if (dis(xx, yy, zz) < dis(x, y, z)) { x = xx; y = yy; z = zz; } } step *= r; } return dis(x, y, z); } int main() { while (~scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f)) { printf("%.7lf\n", solve()); } return 0; }
相关文章推荐
- hdu 5017 Ellipsoid 模拟退火算法 西安网络赛
- hdu 5017 Ellipsoid 模拟退火
- hdu 5017 ellipsoid 退火大法
- hdu 5017 Ellipsoid 模拟退火算法模板
- HDU 5017 Ellipsoid 模拟退火
- HDU 5017 Ellipsoid
- [HDU 5017] Ellipsoid (模拟退火)
- HDU 5017 Ellipsoid 模拟退火第一题
- HDU 5017 Ellipsoid 模拟退火第一题
- HDU 5017 Ellipsoid 模拟退火
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- hdu 5017 Ellipsoid
- hdu 5017 Ellipsoid
- 【计算几何】 HDOJ 5017 Ellipsoid
- HDOJ 5017 Ellipsoid
- 【HDOJ】5017 Ellipsoid
- hdu 5017
- [IDDFS] HDU 1560
- 浙大ACM 2075 Ellipsoid Volume解题报告