hdoj 2199 2899【二分--精度问题】


传送门:2199

传送门:2899


2199代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double y;
double solve(double xx)
{return 8*xx*xx*xx*xx+7*xx*xx*xx+2*xx*xx+3*xx+6;}
int main()
{
    int t;scanf("%d",&t);
    while (t--)
    {
        scanf("%lf",&y);
        if (y<solve(0)||y>solve(100))
        printf("No solution!\n");
        else
        {
            double ans=-1,op,l=0,r=100,m;
            while (r-l>=0.00000001)
            {
                m=(r+l)/2;
                op=solve(m);
                if (op>=y)
                {
                    ans=m;
                    r=m;
                }
                else
                    l=m;
            }
            printf("%.4lf\n",ans);
        }
        
    }
    return 0;
}


2899代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double y;
double solve(double xx)
{return 42*pow(xx,6)+48*pow(xx,5)+21*pow(xx,2)+10*xx;}
int main()
{
    int t;scanf("%d",&t);
    while (t--)
    {
        scanf("%lf",&y);
        double ans=-1,op,l=0,r=100,m;
        while (r-l>=0.00000001)
        {
            m=(r+l)/2;
            op=solve(m);
            if (op>=y)
            {
                ans=m;
                r=m;
            }
            else
                l=m;
        }
        ans=(6*pow(ans,7)+8*pow(ans,6)+7*pow(ans,3)+5*ans*ans-y*ans);
        printf("%.4lf\n",ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值