HDU-2899
2017-02-09 08:52
155 查看
Now, here is a fuction:
F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
Can you find the minimum value when x is between 0 and 100.
InputThe first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)
OutputJust the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
Sample Input
Sample Output
这道题在做的时候,最开始觉得这个函数应该是用三分法解决,但是用了之后,会发现怎么都ac不了,都是
wa,然后在网上查完资料之后,发现这道题就应该是先求导,之后再根据导数的正负,来运用二分法解决问
题,因为我们要求的是一个最值而跟极值的概念还是有不同的,之后将过程实现,就可以ac了,这道题感觉
就是可以运用数学知识解决问题
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
double cal(double x,double y)
{
//6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
return(6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x);
}
double cal_d(double x,double y)
{
return(42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y);
}
int main()
{
int times;
cin>>times;
while(times--)
{
long long y_get;
cin>>y_get;
double low = 0,high = 100;
double mid;
while(low<high-0.000001)
{
mid = (low+high)/2;
if(cal_d(mid,y_get)>0) high = mid;
else low = mid;
}
printf("%.4f\n",cal(mid,y_get));
}
}
F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
Can you find the minimum value when x is between 0 and 100.
InputThe first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)
OutputJust the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
Sample Input
2 100 200
Sample Output
-74.4291-178.8534
这道题在做的时候,最开始觉得这个函数应该是用三分法解决,但是用了之后,会发现怎么都ac不了,都是
wa,然后在网上查完资料之后,发现这道题就应该是先求导,之后再根据导数的正负,来运用二分法解决问
题,因为我们要求的是一个最值而跟极值的概念还是有不同的,之后将过程实现,就可以ac了,这道题感觉
就是可以运用数学知识解决问题
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
double cal(double x,double y)
{
//6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
return(6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x);
}
double cal_d(double x,double y)
{
return(42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y);
}
int main()
{
int times;
cin>>times;
while(times--)
{
long long y_get;
cin>>y_get;
double low = 0,high = 100;
double mid;
while(low<high-0.000001)
{
mid = (low+high)/2;
if(cal_d(mid,y_get)>0) high = mid;
else low = mid;
}
printf("%.4f\n",cal(mid,y_get));
}
}
相关文章推荐
- HDU 2899 Strange fuction(三分)
- hdu 2899 Strange fuction(导数+二分)
- hdu 2899 Strange fuction (求导 + 二分)
- hdu 2899 三分
- hdu 2899 Strange fuction(二分+数学)
- HDU 2899
- day2 HDU - 2899
- hdu 2899 Strange fuction
- HDU 2899 (二分 或者 三分)
- hdu 2899 Strange fuction
- HDU-2899(简单数学问题+二分查找)
- HDU 2899 Strange fuction(二分||三分)
- HDU - 2899 Strange fuction 二分/三分
- HDU 2899 三分
- hdu 2899 (数学+二分)
- hdu 2899 Strange fuction
- HDU 2899 :(二分求最小值)
- hdu 2899 Strange fuction
- HDU 2899 Strange fuction
- hdu 2899