原题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2199
Can you solve this equation?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8116 Accepted Submission(s): 3738
Problem Description
Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;
Now please try your lucky.
Now please try your lucky.
Input
The 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 a real number Y (fabs(Y) <= 1e10);
Output
For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.
Sample Input
2
100
-4
Sample Output
1.6152
No solution!
Author
Redow
Recommend
分析:这道题目就是中学里学的二分法求方程的解的问题,注意符合要求的x,f(x) - Y<=0.000001,这个有精确度确定。
//二分法解方程 HDU 2199 #include<cstdio> #include<cmath> double low,mid,high; int Y,t,flag; using namespace std; double f(double x){ double result = 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6; return result; } int main(){ scanf("%d",&t); while(t--){ scanf("%d",&Y); low = 0.0; high = 100.0; flag = 0; while(low<high) { mid = (low+high)/2; if(fabs(f(mid)-Y)<= 0.000001) { flag = 1; break; }else if(f(mid)-Y>0) { high = mid; }else { low = mid; } } if(flag){ printf("%.4f\n",mid); }else{ printf("%s\n","No solution!"); } } }
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu2101AC代码
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU ACM 2005第几天 C++ http://acm.hdu.edu.cn/listproblem.php?vol=11 2005题 第几天?
HDU最全ac代码
自己做的HDU ACM已经AC的题目
hdu动态规划算法集锦
hdu题目分类
HDU图论题目分类
Hdu 1237 解题代码