二分专攻:HDU 2199(解方程)

二分渐近查找解……
HDU 2199
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
double y;
double f(double x)
{
    return 8*pow(x,4.0)+7*pow(x,3.0)+2*pow(x,2.0)+3*x+6.0;
}
double abc()
{
    double mid,a=0,b=100;
    while(b-a>1e-6)
    {
        mid=(a+b)/2;
        if(f(mid)<y) a=mid+1e-7;
        else b=mid-1e-7;
    }
    return (a+b)/2.0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>y;
        if(f(0)<=y&&f(100)>=y) printf("%.4f\n",abc());
        else printf("No solution!\n");
    }
}

你可能感兴趣的:(二分专攻:HDU 2199(解方程))