HDU 2199 (Binary)

Source: Internet
Author: User

Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2199

Can you solve this equation?

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 8595 accepted submission (s): 3957


Problem descriptionnow, 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.

 

Inputthe 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 );

 

Outputfor each test case, You shocould 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 Input2100-4

 

Sample output1.6152no solution! Average ------------------------------------------------------------------------------------------------------------,
 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <iostream> 5 #include <algorithm> 6 #include <math.h> 7 #define eps 1e-8 8 using namespace std; 9 10 double fx(double x)11 {12     return 8*pow(x,4)+7*pow(x,3)+2*x*x+3*x+6;13 }14 15 int main()16 {17     int n,m,i,j;18     double y;19     double left=0,right=100,ans;20     scanf("%d",&n);21     while(n--)22     {23         scanf("%lf",&y);24         left=0.0,right=100.0;25         //ans=-100000;26         bool flag=true;27         while(right-left>eps)28         {29             double mid=(left+right)/2.0;30             if(fx(mid)-y< 0)31                  left=mid+eps;32             else right=mid-eps;33             //if()flag=false;34         }35         if(y>fx(100) || y<fx(0))36             printf("No solution!\n");37         else38             printf("%.4lf\n",left);39     }40 41 }
View code

 

HDU 2199 (Binary)

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.