当前位置: 代码迷 >> 综合 >> hdu - 2899 - Strange fuction(二分)
  详细解决方案

hdu - 2899 - Strange fuction(二分)

热度:33   发布时间:2024-01-10 13:36:18.0

题意:求F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2899

——>>分类讨论+二分。

#include <cstdio>
#include <cmath>#define F(x) (6*pow(x, 7) + 8*pow(x, 6) + 7*pow(x, 3) + 5*pow(x, 2) - Y*x)
#define g(x) (42*pow(x, 6) + 48*pow(x, 5) + 21*pow(x, 2) + 10*x - Y)using namespace std;const double eps = 1e-14;int main()
{int T;double Y;scanf("%d", &T);while(T--){scanf("%lf", &Y);double MIN;if(g(0) > eps){MIN = F(0);}else if(g(100) < -eps){MIN = F(100);}else{double x = 0, y = 100, m;for(int i = 0; i < 100; i++){m = x + (y - x) / 2;if(g(m) < 0) x = m;else y = m;}MIN = F(m);}printf("%.4lf\n", MIN);}return 0;
}