Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
Now,given the equation *x^ + *x^ + *x^ + *x + == Y,can you find its solution between and ;
Now please try your lucky. Input
The first line of the input contains an integer T(<=T<=) 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 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between and . Sample Input - Sample Output
1.6152
No solution! Author
Redow Recommend
lcy
数学题,直接二分,代码
#include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"cmath"
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define MX 10000 + 50
using namespace std; double f(double x)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x+;
} int main()
{
int n;
double m;
while(~scanf("%d",&n))
{
for(int k=; k<=n; k++)
{
scanf("%lf",&m); double i=0.0;
if(m<f()||m>f())
{
printf("No solution!\n");continue;
}
double fr=0.0,ed=100.0;
for(; fabs(f(fr)-f(ed))>1e-;)
{
i=(fr+ed)/;
if(f(i)<m)fr=i;
else ed=i;
}
{
printf("%.4lf\n",i);
}
}
}
return ;
}