hdu 2289 Cup(数学题)

小记:不知道公式,用二分瞄了很久,还是没A,后来知道应该是没处理特殊情况了,


思路:二分可以,数学方法也可以

如果是圆柱直接就可以求出高

h0 = V/(π*r*r)

如果是圆锥柱,那么求出最上面没有的圆锥的体积,然后根据圆锥体积比是高的比的3倍来求出高

h = r*H/(R-r)

V0 = (PI*h*r*r)/3.0

h0 = h*(pow((V0/(V0+V),1.0/3) - 1)

(V0/(V0+V) )^(1/3)= (h+h0)/h;


如果V0 大于圆锥柱的体积V,那么就相当于h0>H,那么就只能装H,


代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-10
#define PI acos(-1.0)//3.14159265

const int MAX_ = 510;
const int N = 100010;
const int INF = 0x7fffffff;

double r, R, H, V;

int main(){
    int  k;
    double h, h0, V0;
    scanf("%d",&k);
	while(k--){
	    scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
	    if(r == R){
            h0 = V/(PI*r*r);
	    }
	    else if(r < R){
            h = r*H/(R-r);
            V0 = (PI*r*r*h)/3.0;
            h0 = h*(pow((V0+V)/V0, 1.0/3) - 1);
	    }
	    if(h0 > H)h0 = H;
	    printf("%.6lf\n",h0);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值