【三分】HDU3756 Dome of Circus

  • 假设我们枚举一个半径 r ,那么分别考虑包含进每个点圆锥的最小高度h0,h1,,hn1,显然此时如果半径为 r ,圆锥高度应为maxn1i=0 hi,简单推算一下公式,可以发现体积关于半径是个凹函数,于是三分半径即可。
  • 注意初始的半径范围,上限自然可以随便设置一个较大值,但下限需要稍加考虑。设
    di=xi2+yi2
    那么 r 应满足
    r>max{di},0i<n
  • 输入输出部分,即使ios::sync_with_stdio(false)也无法避免cincout的超时问题,所以似乎必须用printfscanf IO
/* **********************************************

    File Name: 3756.cpp

    Auther: zhengdongjian@tju.edu.cn

    Created Time: 2015/9/9 星期三 下午 7:07:06

*********************************************** */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const double EPS = 1e-4;
const double INF = (double)INT_MAX;
const int MAX = 10007;
struct Pos {
    double x, y, z;
} a[MAX];
int n;

istream& operator>>(istream& in, Pos& p) {
    in >> p.x >> p.y >> p.z;
    return in;
}

pair<double, double> gao(double r) {
    double h = 0.0;
    for (int i = 0; i < n; ++i) {
        double dis = a[i].x * a[i].x + a[i].y * a[i].y;
        dis = sqrt(dis);
        //printf("dis = %f\n", dis);
        //getchar();
        double tp = a[i].z / (r - dis) * dis + a[i].z;
        if (tp > h) h = tp;
    }
    return make_pair(h, r * r * h);
}

pair<double, double> cut(double le, double ri) {
    double md, mdmd;
    while (ri - le > EPS) {
        //printf("le = %f, ri = %f\n", le, ri);
        md = (le + ri) * 0.5;
        mdmd = (md + ri) * 0.5;
        if (gao(mdmd).second > gao(md).second) {
            ri = mdmd;
        } else {
            le = md;
        }
    }
    //printf("le = %f, ri = %f\n", le, ri);
    return make_pair(gao(le).first, le);
}

int main() {
    int T;
    scanf(" %d", &T);
    while (T--) {
        scanf(" %d", &n);
        double mindis = 0.0;
        for (int i = 0; i < n; ++i) {
            scanf(" %lf %lf %lf", &a[i].x, &a[i].y, &a[i].z);
            mindis = min(mindis, sqrt(a[i].x * a[i].x + a[i].y * a[i].y));
        }
        //auto res = make_pair(0.0, 0.0);
        auto res = cut(mindis + EPS, 100000.0);
        printf("%.3f %.3f\n", res.first + EPS, res.second + EPS);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值