nHDOJ-2899
给出函数:
F(x) = 6*x7 + 8*x6 + 7*x3 + 5*x2 - y*x
其中,实数y满足 (0
请输出x在区间[0,100]时函数F(x)的最小值,
结果精确到小数点后4位。
指定区间内是否满足单调性?
显然不满足->不能直接二分
满足凸性?
如何证明?
极值点的特点?求导数,为0得出x值,代入原方程,即可求到最大值
是否可以二分?
y只是一个输入,在题目中,它影响到了最值求导
- #include <iostream>
- #include <cmath>
- using namespace std;
- double y;
- double low, high, mid;
- const double eps = 1e-8;
- double cal(double x){
- return 42.0*pow(x,6.0)+48.0*pow(x,5.0)+21.0*pow(x,2.0)+10.0*x;
- }
- double ans(double x){
- return 6.0*pow(x,7.0)+8.0*pow(x,6.0)+7.0*pow(x,3.0)+5.0*pow(x,2.0)-y*x;
- }
- int main()
- {
- int T;
- scanf("%d", &T);
- while(T--)
- {
- scanf("%lf", &y);
- if(cal(100)-y <= 0.0)//导数那里没减y
- {
- printf("%.4lf\n", ans(100.0));
- }
- else
- {
- low = 0.0;
- high = 100.0;
- while((high - low)>eps) //low 与high不要求相等,所以后面的移动不要求判断相等
- {
- mid = (low + high) / 2;
- double temp = cal(mid)-y;
- if(temp>0.0)
- {
- high = mid - eps;
- }
- else
- low = mid + eps;
- }
- printf("%.4lf\n",ans((low+high)/2) );
- }
-
- }
- return 0;
- }
阅读(1179) | 评论(0) | 转发(0) |