Can you solve this equation?
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!
#include <stdio.h>
long int y;
int a[6]={0,6,3,2,7,8};
int solve(double n)
{
double x=1,sum=0;
for(int i=1;i<=5;i++)
{ sum+=x*a[i];
x*=n;}
if(sum>y)
return 1;
else
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t)
{
scanf("%ld",&y);
double min=0,max=100,mid,ans;
if(y>=6&&y<=807020306)
{
while(max-min>1e-8)
{
mid=(min+max)/2;
if(solve(mid))
max=mid;
else
min=mid;
long int y;
int a[6]={0,6,3,2,7,8};
int solve(double n)
{
double x=1,sum=0;
for(int i=1;i<=5;i++)
{ sum+=x*a[i];
x*=n;}
if(sum>y)
return 1;
else
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t)
{
scanf("%ld",&y);
double min=0,max=100,mid,ans;
if(y>=6&&y<=807020306)
{
while(max-min>1e-8)
{
mid=(min+max)/2;
if(solve(mid))
max=mid;
else
min=mid;
}
printf("%.4lf\n",max);
}
else
printf("No solution!\n");
t--;
}
return 0;
}
printf("%.4lf\n",max);
}
else
printf("No solution!\n");
t--;
}
return 0;
}
一道的简单的二分题,精度那里控制不好的会出现WA
快别扯淡了,我什么都不想听