Can you solve this equation?
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 207 Accepted Submission(s) : 76
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;<br>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<br>100<br>-4<br>
Sample Output
1.6152<br>No solution!<br>
Author
Redow
Strange fuction
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 133 Accepted Submission(s) : 65
Problem Description
Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>Can you find the minimum value when x is between 0 and 100.
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 only one real numbers Y.(0 < Y <1e10)
Output
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
Sample Input
2<br>100<br>200
Sample Output
-74.4291<br>-178.8534
Author
Redow
题目要求:第一道是求函数f的零点,而第二道则是求函数导数零点对应的函数值。
思路:其实可以说没有什么变化,只是形式变了变
1通过二分法来求求出方程的近似解
2 通过牛顿迭代法求其近似解
注意事项:1用浮点型储存
#include<iostream>
#include<cstdio>
using namespace std;
double f(double a,double b)
{
return 8*a*a*a*a+7*a*a*a+2*a*a+3*a-b+6;
}
int main()
{
int n,m;double b,e,mid;
scanf("%d",&n);
while(n--)
{
b=0;e=100;
scanf("%d",&m);
if(f(b,m)*f(e,m)>0)printf("No solution!\n");
else{
while(e-b>0.000000001)
{
mid=(b+e)/2;
if(f(mid,m)>0)
e=mid;
else
b=mid;
}
printf("%.4f\n",e);
}
}
}
#include<iostream>
#include<cstdio>
using namespace std;
double f(double a,double b)
{
return 42*a*a*a*a*a*a+48*a*a*a*a*a+21*a*a+10*a-b;
}
double g(double a,double b)
{return 6 * a*a*a*a*a*a*a+8*a*a*a*a*a*a+7*a*a*a+5*a*a-b*a;}
int main()
{
int n,m;double b,e,mid;
scanf("%d",&n);
while(n--)
{
b=0;e=100;
scanf("%d",&m);
if(f(b,m)*f(e,m)>0)printf("No solution!\n");
else{
while(e-b>0.000000001)
{
mid=(b+e)/2;
if(f(mid,m)>0)
e=mid;
else
b=mid;
}
printf("%.4f\n",g(e,m));
}
}
}