题意:给出方程,求解x取0 - 100时的最小值。
# include <iostream>
# include <cmath>
using namespace std;
double f(double x, double y)
{
double fx = 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * pow(x, 2) + 10 * x - y;
return fx;
}
double f1(double x, double y)
{
double fx = 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x;
return fx;
}
int main()
{
int t;
cin >> t;
while(t--)
{
double y;
cin >> y;
double begin = 0, end = 100, mid;
int i = 0;
while(1)
{
mid = (begin + end) / 2;
if(fabs(f(mid, y)) <= 0.0001)
{
cout.precision(4);
cout << fixed << f1(mid, y) << endl;
break;
}
else if(f(mid, y) > 0)
{
end = mid;
}
else if(f(mid, y) < 0)
{
begin = mid;
}
}
}
return 0;
}