1 题目编号:1002
2 题目内容:
2<br>100<br>200
-74.4291<br>-178.8534
3 解题思路形成过程:与problem 1002相似 ,求函数最小解 ,可以对其求导,在一般情况下,当F'(t) =0时,在x=t处有最小值,代入求解,然后利用二分法进行查找即可
4 代码:
#include<iostream>
#include<cmath>
using namespace std;
double g(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 f(double x, double y)
{
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) - x*y;
}
int main(){
int t;
double y, l, h, mid;
cin>>t;
while (t--){
cin>>y;
if (g(100.0) - y <= 0){
cout<< f(100.0, y);
}
else
{
l = 0.0;
h = 100.0;
while (h - l>1e-8){
mid = (h + l) / 2.0;
if (g(mid) - y<0)
l = mid;
else
h = mid;
}
cout<<fixed<<f(mid, y)<<endl;
}
return 0;
}