Title Description
Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 = = Y,can you find its solution between 0 and 100;
Now 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), and which is the solution of the E Quation,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!
Effect
Simple water problem for solving equation
Ideas
Simple water problem, the use of the dichotomy can be. But pay attention to the accuracy of floating point comparison, I write 1e-5, if the accuracy is too high, will time out
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<iomanip>
using namespace std;
double m, res = 0;
int ji = 0;
double f(double res)
{
returnRes*Res*Res*Res* 8 +Res*Res*Res* 7 +Res*Res* 2 +Res* 3 + 6;
}
int main()
{
//cin.sync_with_stdio(false);
//freopen("date.in", "r", stdin);
//freopen("date.out", "w", stdout);
int N, temp;
double b, e, tem = 50;
scanf("%d", &N);
for (int i = 0; i<N; i++){
b = 0, e = 100, tem = 50;
cin >> m;
if (m<6 || m>807020306)
//cout << "No solution!" << endl;
printf("No solution!\n");
else{
while (fabs(f(tem) - m) >= 1e-5)
if (f(tem)>m){
e = tem;
tem = (b + e) / 2;
}
else{
b = tem;
tem = (b + e) / 2;
}
//cout << fixed << setprecision(4) << tem << endl;
printf("%0.4f\n", tem);
}
}
}
From for notes (Wiz)
ACM Course Practice 2--1001