hdu 2899 Strange Fuction(二分)
2012-02-14 23:21
369 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2899 简单二分,但这个不满足单调性。
题目要求极值点,以函数导数的正负作为条件二分即可。
code:
#include<cstdio>
#include<cmath>
double y = 0 ;
double cal(double x){
return 42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x - y ;
}
double solve(double x){
return 6*pow(x, 7.0) + 8*pow(x, 6.0) + 7*pow(x, 3.0) + 5*pow(x, 2.0) - y*x ;
}
int main(){
int t ;
double r, l, m ;
scanf("%d", &t) ;
while(t--){
scanf("%lf", &y) ;
if(cal(100)<=0){ //x=100时若导数小于0,则函数满足单调递减
//因为42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x递增,x=100时有最大值
//不过官方数据好像没有用到这个剪枝
printf("%.4lf\n", solve(100)) ;
continue ;
}
l = 0 ;
r = 100 ;
while(r-l>1e-8){
m = (r + l) / 2 ;
double ans = cal(m) ;
if(ans<0)
l = m ;
else
r = m ;
}
printf("%.4lf\n", solve(m)) ;
}
return 0 ;
}
题目要求极值点,以函数导数的正负作为条件二分即可。
code:
#include<cstdio>
#include<cmath>
double y = 0 ;
double cal(double x){
return 42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x - y ;
}
double solve(double x){
return 6*pow(x, 7.0) + 8*pow(x, 6.0) + 7*pow(x, 3.0) + 5*pow(x, 2.0) - y*x ;
}
int main(){
int t ;
double r, l, m ;
scanf("%d", &t) ;
while(t--){
scanf("%lf", &y) ;
if(cal(100)<=0){ //x=100时若导数小于0,则函数满足单调递减
//因为42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x递增,x=100时有最大值
//不过官方数据好像没有用到这个剪枝
printf("%.4lf\n", solve(100)) ;
continue ;
}
l = 0 ;
r = 100 ;
while(r-l>1e-8){
m = (r + l) / 2 ;
double ans = cal(m) ;
if(ans<0)
l = m ;
else
r = m ;
}
printf("%.4lf\n", solve(m)) ;
}
return 0 ;
}
相关文章推荐
- HDU—2899—strange fuction—【二分】【精度控制】
- HDU 2899 Strange fuction(二分查找根)
- hdu 2899 Strange fuction (二分)
- hdu 2899 Strange fuction 【二分,三分】
- HDU - 2899 Strange fuction 二分/三分
- hdu 2899 Strange fuction 二分
- hdu - 2899 - Strange fuction(二分)
- HDU 2899 Strange fuction 牛顿迭代法 || 二分
- HDU 2899 Strange fuction(二分)
- HDU 2899 Strange fuction 二分 + 精度控制
- HDU--杭电--2899--Strange fuction--二分
- HDU 2899 Strange fuction(二分||三分)
- hdu 2899 Strange fuction(导数+二分)
- HDU 2899 Strange Fuction(二分查找)
- Hdu 2899 - Strange fuction 二分/三分求函数极值点
- HDU 2899 Strange fuction(二分或三分)
- HDU 2899 Strange fuction(二分,三分)
- HDU 2899 Strange fuction 二分求方程解
- Hdu 2899 Strange fuction(二分三分可做,模拟退火解法)
- hdu 2899 Strange fuction(二分+数学)