ACM Course Practice 2--1001

Source: Internet
Author: User

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

  
 
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cmath>
  4. #include<iomanip>
  5. using namespace std;
  6. double m, res = 0;
  7. int ji = 0;
  8. double f(double res)
  9. {
  10. returnRes*Res*Res*Res* 8 +Res*Res*Res* 7 +Res*Res* 2 +Res* 3 + 6;
  11. }
  12. int main()
  13. {
  14. //cin.sync_with_stdio(false);
  15. //freopen("date.in", "r", stdin);
  16. //freopen("date.out", "w", stdout);
  17. int N, temp;
  18. double b, e, tem = 50;
  19. scanf("%d", &N);
  20. for (int i = 0; i<N; i++){
  21. b = 0, e = 100, tem = 50;
  22. cin >> m;
  23. if (m<6 || m>807020306)
  24. //cout << "No solution!" << endl;
  25. printf("No solution!\n");
  26. else{
  27. while (fabs(f(tem) - m) >= 1e-5)
  28. if (f(tem)>m){
  29. e = tem;
  30. tem = (b + e) / 2;
  31. }
  32. else{
  33. b = tem;
  34. tem = (b + e) / 2;
  35. }
  36. //cout << fixed << setprecision(4) << tem << endl;
  37. printf("%0.4f\n", tem);
  38. }
  39. }
  40. }


From for notes (Wiz)

ACM Course Practice 2--1001

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.