poj3737(三分搜索)

题意:给出一个圆锥的表面积(侧面积+底面积),求圆锥的最大体积。

解法:三分半径。左边界随便取个极小的数,右边界可以假定这个圆锥是平的,高是0.这是底面积的二倍是表面积。

代码:

/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std;

#define eps 1e-8
const double pi=acos(-1.0);
typedef long long LL;
const int Max=10100;
const int INF=1000000007;

double v;
double vol(double r)
{
    double tool=v-pi*r*r;
    double len=tool/pi/r;
    double high=sqrt(len*len-r*r);
    return pi*r*r*high/3.0;
}

double gethigh(double r)
{
    double tool=v-pi*r*r;
      double len=tool/pi/r;
    return sqrt(len*len-r*r);
}
int main()
{
    while(scanf("%lf",&v)==1)
    {
        double left=0.1,right=sqrt(v/2.0/pi);
        while(right-left>eps)
        {
            double middle=(left+right)/2;
            double middleright=(middle+right)/2;
            if(vol(middle)>vol(middleright))
                right=middleright;
            else
                left=middle;
        }
        double high=gethigh(left);
        printf("%.2f\n",left*left*pi*high/3.0);
        printf("%.2f\n",high);
        printf("%.2f\n",left);

    }
    return 0;
}

poj3737(三分搜索)

时间: 2024-10-10 21:10:45

poj3737(三分搜索)的相关文章

hdu 4355 Party All the Time(三分搜索)

Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate the harvest every year. But there is one thing you may not know that they hate walking so much that they would prefer to stay at hom

2018/2/12 每日一学 三分搜索

对于二分,设left,right为问题的两个极值,用min=left+(right-left)>>1或mid=(left+right)>>1,可以知道mid值,判断,然后进行更换. 显然,二分适用于单调函数,而对于一个二次函数就无效了. 这时,我们可以用三分搜索来做. 我们定义midl=(left+mid)>>1,midr=(right+mid)>>1.判断midl和midr就行了. 看看代码吧:(转自http://blog.csdn.net/u011787

UVA - 1476 Error Curves (三分搜索)

Description Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In order to test the algorithm's efficiency, she collect

三分搜索

ref:http://blog.csdn.net/acdreamers/article/details/9989197 ref:http://blog.csdn.net/pi9nc/article/details/9666627

hdu 2899 凸性 二分 / 三分

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7230    Accepted Submission(s): 4996 Problem Description Now, here is a fuction:  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

三分套三分 --- HDU 3400 Line belt

Line belt Problem's Link:    Mean: 给出两条平行的线段AB, CD,然后一个人在线段AB的A点出发,走向D点,其中,人在线段AB上的速度为P, 在线段CD上的速度为Q,在其他地方的速度为R,求人从A点到D点的最短时间. analyse: 经典的三分套三分. 首先在AB线段上三分,确定一个点,然后再在CD上三分,确定第二个点,计算出answer.也就是嵌套的三分搜索. Time complexity: O(logn*logm) Source code:  // M

poj 3301 Texas Trip(几何+三分)

Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The local American Tire store sells fiberglass patching material only in square sheets. What is the smallest patch that Harry nee

ZOJ 3203 Light Bulb 三分

最简单的三分题,期末考完先做一道练练手 就是这么一个图,告诉你H h D,问你L最长是多少,假设人到灯的距离是X,那么容易得到 L = H-D/x*(H-h)+D-x,求个导很容易发现是一个关于x 的凸性函数,就可以三分啦 要注意的是三分的时候的精度eps,这题要求得是1e-9才能A,1e-8都WA,真是囧 #include <cstdio> #include <sstream> #include <fstream> #include <cstring> #

2017-9-3 校内模拟T2取数win

题意:给你一个序列,叫你找一个子序列,使得这个子序列的平均数减去中位数最大. 思路:题面直接说是单峰函数,我也没多想(根本没看懂),现在看来就是排序+三分搜索啦. 代码:(特地去学了下三分..): #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int n; long long lefts,rights,lm,mr; int num[200100],presu