hdu 2899

Strange fuction

#include<stdio.h>
#include<math.h>
double f1(double x,double y){
	return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;
}
double f2(double x,double y){
	return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}
int main()
{
	int t;
	double leftthird,rightthird,right,left,n;
	scanf("%d",&t);
	while(t--){
		scanf("%lf",&n);
			left=0.0,right=100.0;
			while(right-left>1e-8){
				leftthird=(left*2+right)/3.0;
				rightthird=(left+right*2)/3.0;
				if(f2(leftthird,n)<f2(rightthird,n))
				right=rightthird;
				else
				left=leftthird;
			}
			 printf("%.4lf\n",f2((left+right)/2.0,n));
		}
	return 0;
}
上一篇:练习2-11 计算分段函数[2] (10分)


下一篇:C语言学习———pow的使用