hdu 5017 Ellipsoid(三分)

题目链接:hdu 5017 Ellipsoid

题目大意:给定一个面的方程,问在面上距离原点的最小值。

解题思路:三分套三分,先三分x,对于每个x,三分y,求出的最优解作为当前x的值。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const double INF = 10000;
const double eps = 1e-9;
double a, b, c, d, e, f;

double get(double A, double B, double C) {
    if (B * B - 4 * A * C < eps)
        return INF;
    return (sqrt(B * B - 4 * A * C) - B) / (2 * A);
}

double func (double x, double y) {
    double z = get(c, e * x + d * y, a * x * x + b * y * y + f * x * y - 1);
    return x * x + y * y + z * z;
}

double search (double x) {
    double l = -INF, r = INF;
    for (int i = 0; i < 200; i++) {
        double ll = l + (r - l) / 3;
        double rr = r - (r - l) / 3;
        if (func(x, ll) > func(x, rr))
            l = ll;
        else
            r = rr;
    }
    return func(x, l);
}

double solve (double l, double r) {
    for (int i = 0; i < 200; i++) {
        double ll = l + (r - l) / 3;
        double rr = r - (r - l) / 3;
        if (search(ll) > search(rr))
            l = ll;
        else
            r = rr;
    }
    return sqrt(search(l));
}

int main () {
    while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) == 6) {
        printf("%.5lf\n", solve(-INF, INF));
    }
    return 0;
}
时间: 2024-10-08 20:04:25

hdu 5017 Ellipsoid(三分)的相关文章

HDU 5017 Ellipsoid(西安网络赛K题)

HDU 5017 Ellipsoid 题目链接 思路:模拟退火大法好! 代码: #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}}; dou

hdu 5017 Ellipsoid(西安网络赛 1011)

Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 850    Accepted Submission(s): 271 Special Judge Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minima

HDU 5017 Ellipsoid (计算几何,模拟退火)

Ellipsoid Problem Description Given a 3-dimension ellipsoid(椭球面) 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 (x1,y1,z1) and (x2,y2,z2) is defined as  Input

hdu 5017 Ellipsoid(模拟退火)

Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1140    Accepted Submission(s): 412 Special Judge Problem Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minim

HDU - 5017 Ellipsoid(模拟退火法)

Problem Description Given a 3-dimension ellipsoid(椭球面) 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 (x1,y1,z1) and (x2,y2,z2) is defined as  Input There are

HDU 5017 Ellipsoid 模拟退火

网赛的时候感觉可以用模拟退火搞但是不会写,今天学了一下感觉模拟退火本身也不是很难= = #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; const double eps = 1e-8; const double r = 0.99; //降温速度 const int dx[] = { 0, 0, 1, -1, 1, -

2014 ACM/ICPC Asia Regional Xi&#39;an Online(HDU 5007 ~ HDU 5017)

题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Sony” 就输出“SONY DAFA IS GOOD!” ,大小写敏感. 思路 : 字符串查找,水题. 1 #include <string.h> 2 #include <stdio.h> 3 #include <iostream> 4 5 using namespace st

codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

B. The Meeting Place Cannot Be Changed The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n

hdu 2899 简单三分

三分就是在二分的基础上的进一步确定区间值      先把区间分为三分            然后更新左右区间值 #include<stdio.h> #include<string.h> #include<iostream> using namespace std; #define exp 1e-6 double y; double pow(double a,int b) { int i; double x=1; for(i=1;i<=b;i++) { x*=a;