noiopenjudge02:二分法求函式的零點 二分
阿新 • • 發佈:2018-12-31
練習二分練習練習二分~~~
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
bool check(double mid)
{
double f = pow(mid,5)-15.0*pow(mid,4)+85.0*pow(mid,3)-225.0*pow(mid,2)+274.0*mid-121.0;
if(f > 0.0) return 1;
return 0;
}
int main()
{
double l = 1.5, r = 2.4, mid;
while(r-l > 0.00000001)
{
mid = (l+r)/2.0;
if(check(mid)) l = mid;
else r = mid;
}
printf("%.6lf", mid);
return 0;
}