Can you solve this equation?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12888 Accepted Submission(s): 5763
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!二分法。代码1:#include<stdio.h> #include<stdlib.h> #include<math.h> double y; double check(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6; } double binary(double left,double right,double y) { while(right-left>1e-8) { double mid=(right+left)/2; if(check(mid)>y) { right=mid-1e-8; } else { left=mid+1e-8; } } return (left+right)/2; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%lf",&y); if(y<check(0)||y>check(100)) { printf("No solution!\n"); } else { printf("%.4lf\n",binary(0,100,y)); } } return 0; }代码2:#include<stdio.h> #include<stdlib.h> #include<math.h> double y; double check(double x) { return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%lf",&y); if(y<check(0)||y>check(100)) { printf("No solution!\n"); } else { double mid; double left=0; double right=100; while((right-left)>1e-8) { double mid=(left+right)/2; double ans=check(mid); if(ans>y) { right=mid-1e-8; } else { left=mid+1e-8; } } printf("%.4lf\n",(left+right)/2); } } return 0; }
本文介绍了一种使用二分法求解特定多项式方程在0到100区间内的实数根的方法,并提供了两段C语言实现的示例代码。
398

被折叠的 条评论
为什么被折叠?



