题目链接: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; }