poj 3737 UmBasketella(三分+求导)

29 篇文章 0 订阅
15 篇文章 0 订阅

【题目大意】:给出一个圆锥体的表面积,求最大的体积,并输出其半径和高。


【解题思路】:下午在比赛的时候是直接求导推的公式做的。

  晚上回来想想其实三分极值可以做,但是一直wa,不知道为什么。

                          我原来三分是这么写的 mid1=(low+high)/2.0; mid2=(mid+high)/2.0; 但是一直过不了,后来改成mid1=low+(high-low)/3.0; mid2=high-(high-low)/3.0;就过了~~不知道什么原因。留着思考....


【代码】:

//三分
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cctype>
#include <map>
#include <iomanip>
                   
using namespace std;
                   
#define eps 1e-10
#define pi acos(-1.0)
#define inf 1<<30
#define linf 1LL<<60
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long

double s;

double solve_v(double r){
    return  pi*r*r*sqrt(pow((s-pi*r*r)/(pi*r),2)-r*r)/3;
}

int main(){
	while (~scanf("%lf",&s)){
		double v=0.0;
		double low=0,high=sqrt(s/pi);
		while (low+eps<high){
			double mid1=low+(high-low)/3.0;
			double mid2=high-(high-low)/3.0;
			double v1,v2;
            v1=solve_v(mid1);
            v2=solve_v(mid2);
            if (v1>v2) v=v1,high=mid2;
			else v=v2,low=mid1;
		}
	    double h=sqrt(pow((s-pi*high*high)/(pi*high),2)-high*high);
	    printf("%.2f\n%.2f\n%.2f\n", v,h,high);
    
    }
	return 0;
}
//求导
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cctype>
#include <map>
#include <iomanip>
                   
using namespace std;
                   
#define eps 1e-8
#define pi acos(-1.0)
#define inf 1<<30
#define linf 1LL<<60
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long

double s,r,h,v,l;

void solve(){
    r=sqrt(s/(4*pi));
    l=s/(pi*r)-r;
    h=sqrt(l*l-r*r);
    v=1.0/3*pi*r*r*h;
}

int main() {
    while (~scanf("%lf",&s)){
        solve(); 
        printf ("%.2f\n",v);
        printf ("%.2f\n",h);
        printf ("%.2f\n",r);
    } 
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值