HDU 2899 :(二分求最小值)

稍微麻烦点的就是需要求导判断最小值的位置

#include"cstdio"
#include"cstring"
#include"algorithm"
#include"cmath"
#define MAXN 505
using namespace std;
double cal(double x,double y){
    return (6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x);
}
double cal1(double x,double y){
    return (42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y);
}
int main()
{   int T;
    scanf("%d",&T);
    while(T--)
    {   double ans,y;
        scanf("%lf",&y);
        double low=0.0,high=100.0,mid;
        while(high-low>=1e-8)
        {   mid=low+(high-low)/2.0;
            if(cal1(mid,y)>=0&&cal1(low,y)<=0) high=mid;
            else if(cal1(high,y)>=0&&cal1(mid,y)<=0) low=mid;
        }
        printf("%.4lf\n",cal(mid,y));
    }
    return 0;
}
时间: 2024-10-30 14:07:33

HDU 2899 :(二分求最小值)的相关文章

POJ 3258- River Hopscotch(二分求最小值最大)

River Hopscotch Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3258 Appoint description:  System Crawler  (2015-05-27) Description Every year the cows hold an event featuring a peculiar version

HDU 2199(二分求方程解)

关键是确定解的范围以及二分时的判断依据 这里解的范围已经确定,因为是递增函数,二分依据就是和Y的大小比较 #include"cstdio" #include"cstring" #include"algorithm" #include"cmath" #define MAXN 505 using namespace std; double cal(double x) { double temp=8.0*pow(x,4)+7.0*p

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

Hdu 2899 - Strange fuction 二分/三分求函数极值点

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4527    Accepted Submission(s): 3251 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

HDU - 1588 Gauss Fibonacci (矩阵快速幂+二分求等比数列和)

Description Without expecting, Angel replied quickly.She says: "I'v heard that you'r a very clever boy. So if you wanna me be your GF, you should solve the problem called GF~. " How good an opportunity that Gardon can not give up! The "Prob

hdu 2899 Strange fuction (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值.注意精确度的问题. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 double y; 6 7 doub

hdu 2680 最短路径(dijkstra算法+多源最短路径单源化求最小值)

Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7062    Accepted Submission(s): 2301 Problem Description One day , Kiki wants to visit one of her friends. As she is liable

HDU 2899 Strange fuction 二分

1.题意:给一个函数F(X)的表达式,求其最值,自变量定义域为0到100 2.分析:写出题面函数的导函数的表达式,二分求导函数的零点,对应的就是极值点 3.代码: 1 # include <iostream> 2 # include <cstdio> 3 # include <cmath> 4 using namespace std; 5 const double eps=1e-8; 6 double Y; 7 int sgn(double x) 8 { 9 if(fa

HDU 2899 Strange fuction (模拟退火)

题目链接:HDU 2899 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100) Can you find the minimum value when x is between 0 and 100. Input The first line of the input contains an integer T(1<=T<=100) which mean