码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2199 (二分&三分 _A题)解题报告

时间:2018-01-24 00:46:58      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:span   技术   ring   splay   bit   pos   its   none   printf   

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199

-----------------------------------------------------------------------------------

题意:8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求解

思路:判断下导数,二分法求解。

代码:

技术分享图片
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-7;

double cal(double x,double Y){
    return  8*pow(x,4) + 7*pow(x,3) + 2*pow(x,2) + 3*x + 6 - Y;
}

double bsearch(double Y){
    double left =0;
    double right=100;
    double mid=0;
    while((right-left)>eps){
        mid = (right+left)*0.5;
        if(cal(mid,Y)>0){
            right =mid;
        }else{
            left =mid;
        }
    }
    return mid;
}

int main(void){
    int T =0;
    scanf("%d",&T);
    for(int i=0;i<T;i++){
        long long int Y =0;
        scanf("%lld",&Y);
        if(cal(0,Y)*cal(100,Y)>0){
            printf("No solution!\n");
        }else{
        double ans =bsearch(Y);
        printf("%.4lf\n",ans);
        }
        
    }

    return 0;

}
View Code

 

HDU 2199 (二分&三分 _A题)解题报告

标签:span   技术   ring   splay   bit   pos   its   none   printf   

原文地址:https://www.cnblogs.com/caomingpei/p/8338375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!