题意:有个方程组为\(F(x) = 6*x^6 + 8*x^6 + 7*x^3 + 5*x^2 - y*x\)\(定义域为[0, 100]\),求它的最小值,每次给定一个实数y。

分析:可以发现这个函数的导函数为增函数,我们可以二分求出零点,然后在零点下面的值为负,在零点上面的值为正,代表原先的函数图像为凹函数。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
const double eps = 1e-6;

double y;

double f(double x)
{
	return 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3) + 5 * pow(x, 2) - y * x;
}

//斜率
double f2(double mid)
{
	return 42 * pow(mid, 6) + 48 * pow(mid, 5) + 21 * pow(mid, 2) + 10 * mid - y;
}

int main()
{	
	int t;
	scanf("%d", &t);

	while (t--)
	{
		cin >> y;

		double l = 0.0, r = 100.0;
		while (r - l > eps)
		{
			double mid = (l + r) / 2;
			if (f2(mid) < eps) l = mid;
			else r = mid;
		}

		printf("%.4lf\n", f(l));

	}

	return 0;
}