FZU 2095 水面高度 (数学题)

Description

kk手上有个长方体,三边长AC,AB,AD分别为a,b,c,现在里面的水高度为d(0<=d<=c)。现在kk将长方体沿AB边翻转,当C点的高度为x(0<=x<a)时,求水面高度。

Input

第一行一个整数T,表示有T(1<=T<=1000)组数据。

每组数据输入五个整数:a b c d x (10<=a,b,c<=100)。

Output

每组数据输出一行,表示水面高度,结果保留两位小数。

Sample Input

215 10 20 10 1283 33 26 18 7

Sample Output

12.0021.44
这是一道几何题,可以直接推出公式,我写了一个水面高度为h,求面积的函数,二分答案验证。
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
using namespace std;
const int mod=1e9+7;
const int N=10005;
double a,b,c,h1,h2,top,d;
int cnt=0;
double get(double h)
{
    if(cnt>100) return 0;
    if(h>=h1+h2)
    {
        return a*c;
    }
    if(h>h1&&h>h2)
    {
        return a*c-get(h1+h2-h);
    }
    double ag;
    if(h>=h1)
    {
        ag=asin(h1/a);
        return a/cos(ag)*h1/2+(h-h1)*a/cos(ag);
    }
    if(h>=h2)
    {
        ag=asin(h2/c);
        return c/cos(ag)*h2/2+(h-h2)*c/cos(ag);
    }
    return h/h1*h/h2*a*c/2;
}
int main()
{
    int i,j,k,T;
    scanf("%d",&T);
    while(T--)
    {
        int zz=1000;
        scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&h1);
        if(h1==0)
        {
            printf("%.2f\n",d);
            continue;
        }
        if(h1==a)
        {
            printf("%.2f\n",a*d/c);
            continue;
        }
        double s=a*d;
        double ag=asin(h1/a);
        h2=c*cos(ag);
        double l=0,r=h1+h2;
        while(zz--)
        {
            double mid=(l+r)/2;
            cnt=0;
            double hav=get(mid);
            if(hav>s) r=mid;
            else l=mid;
        }
        printf("%.2f\n",l);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值