Description
现在,给出等式8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y,请找出他在0和100之间的解(包含0和100)。
现在,请你试试运气。。。。
Input
输入的第一行包含一个整数T(1 <= T <=100),表示测试用例的数目。接下来T个数字,每一行都有一个实数Y(abs(Y)<=10^10);
Output
对于每个测试用例,如果有解,你应该输出一个实数(精确到小数点后4位,四舍五入),如果在0到100之间无解,就输出“No solution!”。
Sample Input
2
100
-4
Sample Output
1.6152
No solution!
题意:输入一个y,找出它的解X(0,100)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
double p(double mid)
{
return 8.0*pow(mid,4.0)+7.0* pow(mid,3.0) + 2.0* pow(mid,2.0)+ 3.0*mid+6.0;
}
int main()
{
double y;
int t;
scanf("%d",&t);
while(t--)
{
double l,r;
double num=8.0*pow(100.0,4.0)+7.0* pow(100.0,3.0) + 2.0* pow(100.0,2.0)+ 306.0;
scanf("%lf",&y);
if(y<6||y>num)
printf("No solution!\n");
else
{
l=0.0,r=100.0;
int Size=100;
while(Size--)
{
double mid=(l+r)/2.0;
if(p(mid)<y)
l=mid;//右区间
else
r=mid;//左区间
}
printf("%.4lf\n",l);
}
}
return 0;
}