标签:
题目大意:
给出一个方程, 6 * x^7+8*x^6+7*x^3+5*x^2-y*x,输入y,求该方程的最小值,x的变化范围为0-100
解题思路:
先对方程求导,倒数为0时的x满足方程的最小值
代码:
#include <iostream> #include <cmath> #include <iomanip> using namespace std; double get(double mid,double y) { return 6*pow(mid,7)+8*pow(mid,6)+7*pow(mid,3)+5*mid*mid-mid*y; } double get1(double mid) { return 42*pow(mid,6)+48*pow(mid,5)+21*pow(mid,2)+10*mid; } double get0(double y) { double mid,low,high; low=0,high=100; while(high>low+0.0000001) { mid=(high+low)/2; if(get1(mid)<y) low=mid+0.0000001; else high=mid-0.0000001; } return mid; } int main() { int T; double Y; cin>>T; while(T--) { cin>>Y; cout<<setiosflags(ios::fixed)<<setprecision(4)<<get(get0(Y),Y)<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/Sikaozhe/p/5349663.html